Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to make a starter hair, why this code is not work? Roblox Studio

Asked by 4 years ago
Edited 4 years ago
01player = game.Players.LocalPlayer
02character = player.Character
03HatClone = game.ReplicatedStorage.GokuHair:Clone()
04 
05function clone()
06    game.ReplicatedStorage.GokuHair:Clone()
07    HatClone.Parent = character
08end
09 
10game.Players.PlayerAdded:Connect(clone)

2 answers

Log in to vote
0
Answered by 4 years ago

I think the problem here is that you are calling the function when the PLAYER has been added, when the player gets added it takes a small amount of time before your character spawns in. I would suggest you try to use .CharacterAdded and see if that works.

Ad
Log in to vote
0
Answered by 4 years ago

Be sure your script is located inside of the Workspace or the ServerScriptService and be sure it's not a localscript! Your script was not working because you didn't wait for the Player's character to spawn. Also, you should clone the hat inside of the function.

New Script:

1function clone(Player)
2    local HatClone = game.ReplicatedStorage.GokuHair:Clone()
3    Player.CharacterAdded:Connect(function(Char)
4        HatClone.Parent = Char
5    end)
6end
7 
8game.Players.PlayerAdded:Connect(clone)

Answer this question