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

Why doesn't PlayerAdded work in StarterGui?

When the (global) script is in Workspace the text is (obviously) printed. However, when the (global) script is in a TextButton in a Frame in a ScreenGui in StarterGui, nothing is printed and no errors are displayed.

game.Players.ChildAdded:connect(function(player)


print('a player has been added, yay')

end)

Should the script be a LocalScript? What am I doing wrong?

2 answers

✓ Accepted answer

The script is replicated to the player after the player joins. Put the script in something that isn't "Starter..." and you should be fine.

Try changing it to localscript and always when you test do start server. In StarterGui there's a checkbox labeled "ResetPlayerGuiOnSpawn" I would try disabling that first then seeing what happens, but since the startergui doesn't work like the workspace does the function would only fire if you already have a player in the game and somebody else joins him/her then his script would fire but not the person that just joined..

Btw in your script I would change ChildAdded to PlayerAdded

game.Players.PlayerAdded:connect(function(player) 


print('a player has been added, yay')

end)

2 comments

0

PlayerAdded and ChildAdded are exactly the same function, so it's personal preference.

0

In this case, since you're using the event on Players.

This discussion is preserved as it was. New answers, comments, and votes are closed.