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

PlayerAdded load hat?

What's wrong with this? Have a similar one that is working in studio but not in game.

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)	
save = player.HatSave.Value

for i,v in pairs(player:GetChildren()) do
if v.ClassName == "Hat" and v.Name == save then
v.Parent = player.Character
end
end	

wait(2)
for i,v in pairs(character:GetChildren()) do
if v.ClassName == "Hat" and v.Name ~= save then
v:Destroy()

end
end
end)

1 answer

✓ Accepted answer

Let's start by tabbing your code correctly:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)   
		save = player.HatSave.Value

		for i, v in pairs(player:GetChildren()) do
			if v.ClassName == "Hat" and v.Name == save then
				v.Parent = player.Character
			end
		end 

		wait(2)

		for i, v in pairs(character:GetChildren()) do
			if v.ClassName == "Hat" and v.Name ~= save then
				v:Destroy()
			end
		end
-- If you had tabbed correctly, you would have realized you are missing an `end)` here!
end)

1 comment

0

thanks mate

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