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

[SOLVED] Removing Hats Script -- Not working?

Asked by 11 years ago

So, I have a script that manipulates multiple things inside the character and fires when someone enters the game, or respawns (or dies).

01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAdded:connect(function(c)
03    print'fetching player'
04    repeat wait() until
05    player.Character
06    print'fetching character'
07    local char = player.Character
08    local hum = char.Humanoid
09    local head = char.Head
10    head.Transparency = 1
11    print'invisible head and no name'
12    hum.WalkSpeed = 50
13    for _, v in pairs(char:GetChildren()) do
14        wait()
15    if v:IsA("Hat") then
View all 34 lines...

So far, everything in this script is working well, except for one thing.

1for _, v in pairs(char:GetChildren()) do
2        wait()
3    if v:IsA("Hat") then
4        v:Destroy()
5    end
6    end

The above code is not firing.

Help?

1 answer

Log in to vote
1
Answered by
AxeOfMen 434 Moderation Voter
11 years ago

It is possible that the hat is being added to the character after your code has already executed. You may want to consider using a ChildAdded event handler to remove hats as they are added to the character.

1char.ChildAdded:connect(function(child)
2    if child:IsA("Hat") then
3        child:Destroy()
4    end
5end)
0
Thank you :) keitheroni 45 — 11y
Ad

Answer this question