Hello, how would I go about finding the owner of an entity, as in the player who spawned it? I tried self:GetOwner():GetName() but that didnt seem to work...
Thanks for the help!
I believe you need to set the owner of the prop when it is spawned. GetOwner() returns a null entity because SetOwner() wasn't called anywhere for the entity the player spawned.
[QUOTE=Remixful;51255799]I believe you need to set the owner of the prop when it is spawned. GetOwner() returns a null entity because SetOwner() wasn't called anywhere for the entity the player spawned.[/QUOTE]
int my Initialization function I put self:SetOwner(LocalPlayer()) and used self:GetOwner() in my ENT:Use function, returns error: attempt to call gloval 'LocalPlayer' (a NIL value)
[QUOTE=Cosmo;51255827]int my Initialization function I put self:SetOwner(LocalPlayer()) and used self:GetOwner() in my ENT:Use function, returns error: attempt to call gloval 'LocalPlayer' (a NIL value)[/QUOTE]
LocalPlayer does not exist in the server realm.
Try something like this
[CODE]hook.Add("PlayerSpawnedProp","setentowner",function(ply, model, ent) ent:SetOwner(ply) end)[/CODE]
[editline]
[/editline]
Don't do this, read below.
Don't do that, entities won't collide with player
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetCreator]Entity:GetCreator[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetCreator]Entity:SetCreator[/url]
[QUOTE=gonzalolog;51256057]Don't do that, entities won't collide with player
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetCreator]Entity:GetCreator[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetCreator]Entity:SetCreator[/url][/QUOTE]
Thanks for correcting me. I should've read the wiki page more carefully.
[QUOTE]Sets the owner of this entity , disabling all physics interaction with it.[/QUOTE]
I've done some more research and found this as well.
[IMG]https://i.gyazo.com/52f0c326a67f36280dd4de7895cf2dfa.png[/IMG]
Hopefully this helps others learning like myself.
Hmm, I will look more into these options. Thank you to everyone who took the time to reply. -Solved.
I used self:GetCreator():GetName() and it seemed to work perfectly, again, thanks guys.
Sorry, you need to Log In to post a reply to this thread.