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

How do I make it so this script can find a hat object (named whatever the hat is) in this script?

Asked by 9 years ago

here is the script;

while true do
    local Player = LocalScript.Parent
if Player ~= nil then
    Player.TeamColor = game.Teams.Zombies.TeamColor
    Player:WaitForChild(Shirt)
Player.Shirt:Destroy()
    Player:WaitForChild(Pants)
Player.Pants:Destroy()
    Player:WaitForChild(BodyColors)
b=Player.BodyColors
    b.HeadColor = "Medium Green"
b.LeftArmColor = "Medium Green"
    b.LeftLegColor = "Brown"
b.RightArmColor = "Medium Green"
    b.RightLegColor = "Brown"
b.TorsoColor = "Brown"
    Player:WaitForChild(ShirtGraphic)
Player.ShirtGraphic:Destroy()



end
end

1 answer

Log in to vote
0
Answered by
Defaultio 160
9 years ago

There are a few issues that I can see here. It looks like you've got this script in a player's character, which is fine, but if the script is a LocalScript, as line 2 suggests, this won't work in online mode; only in solo mode. LocalScripts only work inside of Tools, HopperBins, or inside of the Player. So make it a script, if it's not!

Also, consider the case in which the player is not wearing a Shirt or Pants. I'm not sure of this, but if this is so, I don't think there's going to be a Shirt or Pants object there. So your script is going to yield indefinitely when you attempt to call :WaitForChild() for something that's not there.

Now, onto your question. Unlike other clothing types, hats are always named different things, so the method is a little bit different. What they do have in common, though, is that they are all Accoutrements. You will have to search through the character, and if anything you find is an accoutrement, you can destroy it. So here we go:

for _, v in pairs(Player:GetChildren()) do
    if v:IsA("Accoutrement") then
        v:Destroy()
    end
end

Hope this helps!

0
Thank you! zachhg03 35 — 9y
Ad

Answer this question