• How can I check if the player spawns an entity?
    1 replies, posted
So I'm pretty new to LUA, and I was trying to make the player's spawned entities to get removed when they disconnect. I planned on checking if the player spawned an entity and setting its owner to the player that spawned it and when a player disconnects the code cycles trough all the entities and check if the player that disconnected owns it and removes it, but I don't know how to check if the player spawned in an entity. I'm sorry if I'm making a post that's already answered, I'm pretty new in the forums as well.
By default, after an entity is created, the game forgets which player made it. You will have to write code to keep track of it. When a prop is spawned, the hook PlayerSpawnedProp is called (use hook.Add to use it). There you can mark, in whichever way you want, which player created what. Don't use SetOwner, it's not what you think. You will have to do the same thing with PlayerSpawnedRagdoll, PlayerSpawnedSENT and so on (see the sidebar on the wiki for other types). Then, when a player disconnects (PlayerDisconnected) you remove the entities they've spawned. I hope that helps!
Sorry, you need to Log In to post a reply to this thread.