Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.