PlayerAdded Alternative (in StarterGui)?

Is there an alternative to PlayerAdded that would cause a specific script in StarterGui to run locally every time a player joins, similarly to how PlayerAdded works outside of StarterGui? I’ve been wondering this for a while, but I’ve found no sufficient answer. I’ve read through several posts relating to this issue, but no sufficient answers were ever given.

game.Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " has joined the server")
end)

For example, the script above does not work when the parent is StarterGui, or any object inside of StarterGui for that matter. Changing the type of script (Script, LocalScript, etc.) doesn’t work either. The project I am working on requires that the script’s parent must be StarterGui, or an object inside of StarterGui.

Please help!

1 Like

Hello,

Can you please explain what your project is? Because starter GUI runs on the client and therefore you wouldn’t need to get specific player values like that.

If you’re trying to get the localplayer locally you don’t need to use PlayerAdded in this case. PlayerAdded does work in StarterGui/anywhere else but it has no time to detect your player being added, it will detect players that join after you however.

You can just do game:GetService("Players").LocalPlayer to get your player

1 Like

Well, I want the specific script to run every time a new player has joined, so LocalPlayer wouldn’t work for my script…

That’s better suited for a server script in ServerScriptService then. StarterGui will only allow the script to run after it clones it to the player’s PlayerGui, meaning it’ll ignore you and the players in the server before you joined, it’ll only run for the players that join after you.

Why do you need it local exactly?

Players.PlayerAdded works in localscripts according to the API documentation, are you testing this in studio? If so, you are most likely loading in before the script exists to fire.

you could do game.Players.ChildAdded i guess cuz i used that for my leaderboards gui

Sorry for restarting but couldn’t you just use remote events?

If you could explain further or post more of your script that would be great, because PlayerAdded does work inside StarterGui local scripts.