How to run a script when a player joins?

Hello! I know this is a silly question but i need to know the answer. Im trying to make a script run when a player joins and not when the die. Thisis a obby game and i dont want the player have to restart when the die. The script im using is this:

game.Players.PlayerAdded:Connect(function(player)
	print("someone joined")
end) 

Any help? Thanks!

7 Likes

This will only run when the player joins and does not run when the player dies

1 Like

Ok? Im confused because if i reset it takes me back to the main menu

robloxapp-20200705-1555523.wmv (450.7 KB)

2 Likes

That sounds like a separate issue. It seems like you have your UI set to reset on spawn. That piece of code right there that you posted in OP will only run when a player joins

All other scripts and UIs will run whenever they’re set to. That script right there does one thing: Print "someone joined" when a player joins.

1 Like

That looks like an issue with having ResetOnSpawn on on a starterGui object. I would have it start in a folder in replicated storage and change it’s parent to the localplayer’s Gui.

2 Likes

Probably this, but I would instead put it in StarterPlayerScripts, which is an easier way to store a LocalScript that won’t reset on death.

6 Likes

Ok thank you for your help! (30 chars)

This worked for me! Thanks! (why do they have this stupid 30 chars thing)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.