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?
The :IsA() method doesn't work with hats. Try replacing the :IsA() with if v.className == "Hat" then
.