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 3 years ago
Edited 3 years ago
player = game.Players.LocalPlayer
character = player.Character
HatClone = game.ReplicatedStorage.GokuHair:Clone()

function clone()
    game.ReplicatedStorage.GokuHair:Clone()
    HatClone.Parent = character
end

game.Players.PlayerAdded:Connect(clone)

2 answers

Log in to vote
0
Answered by 3 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 3 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:

function clone(Player)
    local HatClone = game.ReplicatedStorage.GokuHair:Clone()
    Player.CharacterAdded:Connect(function(Char)
        HatClone.Parent = Char
    end)
end

game.Players.PlayerAdded:Connect(clone)

Answer this question