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

Why dosn't this script work?

Asked by 9 years ago

I am trying to make a tool that makes you invisible for the duration you hold it for. What I wanted to do was, for the hats, examine the Character for any hats using an in pairs loop. I wanted to remove all of the hats from the character and put it into the "Lighting" service. This is my code:

tool = script.Parent

player = game.Players.LocalPlayer

tool.Equipped:connect(function() local Hat = player.Character:GetChildren()

for i,v in pairs(Hat) do
    if v:IsA("Hat") then
        local Hat2 = v:Clone()
        Hat2.Parent = game.Lighting
        Hat2.Name = (player.Name.."'s Hat")
        v:Destroy()
    end
end

end)

This is only for the Dissapearing process. Keep in mind that this is in a LocalScript. I find myself troubled by he fact that I always get 1 extra hat in Lighting, causing EXTREME lag later. can someone please tell me how to fix this?

1 answer

Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

The :IsA() method doesn't work with hats. Try replacing the :IsA() with if v.className == "Hat" then.

Ad

Answer this question