Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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)
0
You've already done it, and they won't ever run until the Player exists Ziffixture 6913 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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!

0
You make the same thing that I did. you dont need to check plr.Character, but on player added not exist character. yHasteeD 1819 — 5y
0
The character may already exist, however. It's always good to check first. joritochip 705 — 5y
0
Also, I responded before you? joritochip 705 — 5y
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 yHasteeD 1819 — 5y
View all comments (3 more)
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. joritochip 705 — 5y
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 yHasteeD 1819 — 5y
0
It's a very rare occurrence but I've always used this method since it happened so my scripts don't break :P joritochip 705 — 5y
Ad

Answer this question