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

PlayerAdded load hat?

Asked by
RoyMer 301 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

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)
0
thanks mate RoyMer 301 — 8y
Ad

Answer this question