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

How do i locate the "Hat" trough a script?

Im new to scripting but im learning....

im trying to create a script that removes clothes,hats,pants from players at the start. ive come up with this:

player = script.Parent.Parent
mouse = player:GetMouse()
character = player.Character
wait(0.1)
print(character)

wait(5)
character.Pants:Remove()
character.Shirt:Remove()
hat = character.Hat
hat:Remove()

my problem is the following:

hats tend to have diffrent names (mine is: WizardHatWithBeard) so doing

character.Hat:Remove()

wont work. Doing...

character:GetFirstChild("Hat")

wont work either.

So is there a way to search for the specific class? like removing all shirts, pants, hats

1 answer

Since hats do not have a specific name and users can have multiple hats, it would be best to use a loop to check to see if each instance in their character is a hat and you can also use this for shirt and pants in case the shirt/pants are not named 'Shirt' or 'Pants'.

for k, r in pairs(player.Character:GetChildren()) do
	if r:IsA('Hat') or r:IsA('Shirt') or r:IsA('Pants') then
		r:Remove()
	end
end

1 comment

0

Thanks! :)

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