✓ Accepted answer
This is not working because you're using a script instead of a LocalScript.
You said that when you put it into a LocalScript it didn't work at all. This is almost certainly because you're putting it it the wrong place.
LocalScripts do not work in Workplace or ServerScriptService. Place a LocalScript with your code in StarterPack or ReplicatedFirst and it should work fine.
When making the change you can get rid of line 1 of your LocalScript. You can do this because when a player gets added, StarterPack and ReplicatedStorage will run the scripts for the player when they join. So we know they exist. There's no need to double check.
The LocalScript will not run until the game replicates the LocalScript to the player.
Good Luck!