You are running this inside of a local script, where is this local script located?
In order for the code to run it must be a desendent of PlayerGui, PlayerScripts or the player’s character.
Make sure it is under one of these locations and the event is being triggered:
- Under PlayerAdded:Connect add a print statement so you can confirm the handler is running.
Secondly, because this is a local script you should only be doing this action for the current player.
This can be done through Players.LocalPlayer rather than the PlayerAdded event.
- Avoid using PlayerAdded in local script as you only need to check the current player
Alternatively, you could move this into a server script and continue to use the PlayerAdded event.
This would be the best option since it gives the server control of the checks and any changes will be replicated to all clients.
- Move the code into a script under ServerScriptServer, this must be a Script not a LocalScript