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

Why is my hat remover script not removing hats?

Asked by 8 years ago

Script:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        wait()
        local d = chr:FindFirstChild("Hat")
        for i,v in pairs(d) do
            v:Destroy()
        end
    end)
end)

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

It isn't working because it is looking for a child inside the players character that is called "hat". Try this instead:

while wait() do
    for i,v in pairs(game.Players:GetPlayers()) do
        if workspace:FindFirstChild(v.Name) then
            local char = workspace:WaitForChild(v.Name)
            for i,v in pairs(char:GetChildren()) do
                if v.ClassName == "Hat" then
                    v:Destroy()
                end
            end
        end
    end
end
0
Doesn't work. :( Rodmane234 85 — 8y
0
Okay I have changed the code, now see if it works. spyro10jf 27 — 8y
0
Now it works. Thanks a lot. Rodmane234 85 — 8y
0
No problem. spyro10jf 27 — 8y
Ad

Answer this question