So a LocalScript
can only be used locally for a player. In that case, you can use game.Players.LocalPlayer
. Any changes made from a LocalScript
will only be seen from the client, not anyone else in the server. If you'd like to clone a hat when a player first joins the game, then you would have to use PlayerAdded
event.
1 | game.Players.PlayerAdded:Connect( function (plr) |
2 | local char = plr.Character |
3 | local hat = game.ServerStorage.Hat:Clone() |
This script will run everytime a new player joins. If you want the hat to clone everytime the player respawns, you should create a ServerScript and place it in StarterPlayer
> StarterCharacterScripts
. Since this script is in StarterCharacterScripts
, it will be cloned into the player everytime the player respawns or joined. In this case, you're allowed to use both LocalScript
s and ServerScript
s. LocalScript
changed are still made local because they are scripts only being run for the client.
01 | local char = script.Parent |
04 | for i,v in pairs (char:GetChildren()) do |
05 | if v:IsA( "Accessory" ) then |
10 | local hat = game.ServerStorage.Hat:Clone() |