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

Help with hat removing?

I want when I touch this part, all hats in my character get removed.

Part = script.Parent

Part.Touched:connect(function(hit)

	for i,v in pairs(hit.Parent:GetChildren()) do
		v.Transparency = 1
		if v:IsA("Hat") then 
			v:remove()
		
		end
	end	
end)

1 answer

First of all, the remove method is deprecated, you should be using destroy instead. Now, as to why this isn't working, you're attempting to set the Transparency property of all children of the character. Not all children of the character have a Transparency property, so you'll get an error when trying to set the property on a child that doesn't have it.

Here's a more robust version, tested and it's working:

script.Parent.Touched:connect(function(hit)
	-- Verify the thing that touched the part is actually a player
	if hit.Parent:FindFirstChild("Humanoid") then
		for i, v in pairs(hit.Parent:GetChildren()) do
			if v:IsA("Hat") then
				v:Destroy();
			end
		end
	end
end)

2 comments

0

Whats about the transparency?

0

@PreyStar what exactly are you trying to do? Remove the hats and set the player's parts to transparent?

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