I have an OnPlayerAdded and CharacterAdded function that I only want to happen when the player joins. How can I do this?
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
print(plr .. "spawned")
end)
end)
I have an OnPlayerAdded and CharacterAdded function that I only want to happen when the player joins. How can I do this?
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
print(plr .. "spawned")
end)
end)
You are mostly correct but the Character may already be loaded. Try this instead:
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
print(plr.Name .. " spawned for the first time!")
end)
If this worked, make sure to mark it as correct/upvote! Thanks!
You make the same thing that I did. you dont need to check plr.Character, but on player added not exist character.
The character may already exist, however. It's always good to check first.
Also, I responded before you?
Could not exist when the player is added That never happened to me. It is not possible at the same time that the player is added the character too
It has happened to me before, and it's better safe than sorry. Just because you haven't experienced it doesn't mean it won't happen.
Oh, anyway. I gave upvote in your reply because as you said happened to you, I always thought it was impossible because I never saw any reports of errors in this, and it never happened to me
It's a very rare occurrence but I've always used this method since it happened so my scripts don't break :P
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
You've already done it, and they won't ever run until the Player exists