Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make an OnPlayerAdded and CharacterAdded function only happen when player joins?

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)

1 comment

0

You've already done it, and they won't ever run until the Player exists

1 answer

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!

7 comments

0

You make the same thing that I did. you dont need to check plr.Character, but on player added not exist character.

0

The character may already exist, however. It's always good to check first.

0

Also, I responded before you?

0

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

0

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.

0

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

0

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.