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

How would I be able to get the hat's handle in character?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

I already have the character defined, but i'm not quite sure how to find the hats. I plan for the hats to turn invisible, for another script I was making.

local Player = Game.Players.LocalPlayer
local Char = Player.CharacterAdded:wait() 
local Hats = Char:getChildren()

    for i = 1,#Hats do
        if Hats[i].ClassName == "Hat" then
            hat = Hats[i]:FindFirstChild("Handle")
                hat.Transparency = 1
                                    end
                                        end

I'm not sure why it's not working. No errors in output.

0
Hats are not loaded as soon as the character is, consider using a wait of about 2 to give the character some time to load it's hats. General_Scripter 425 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()

for i, v in next, character:GetChildren() do
    if v:IsA("Hat") then
        if v:FindFirstChild("Handle") then
            print("There is the handle")
        end
    end
end

I'll explain all the code here :

local player is for defining a variable. Here we defined the local player.

local character is for defining a variable. Here we defined when the character is added in the local player.

for i, v in next, character:GetChildren() do. Here we opened a loop with for. i is the index. v is the childs in the variable character.

:GetChildren() is for taking all thing in the variable character.

if v:IsA("Hat") then Here we open a condition if in the character there is a class named "Hat" then.

if v:FindFirstChild("Handle") then Here we open another condition if in the v, there is a part named "Handle" then.

print("There is the handle") is for printing in the output

sorry for my bad english o-o

I hope its will help you!

Ad

Answer this question