Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

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.

1 answer

✓ Accepted answer
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!

This discussion is preserved as it was. New answers, comments, and votes are closed.