Issue with hat removal

Nothing is printed, no hats are destroyed.

I do not know what could be causing this, since I have 3 hats equipped, but they arent destroyed.
Anyone know how to fix this?

Code:

--local c = character yadda yadda yadda etc

for i,v in pairs(c:GetDescendants()) do
	if v:IsA("BasePart") and v.Parent:IsA("Accessory") then
		print(v,"2")
		v.Parent:Destroy()
	end
end

Any help is appreciated.

This should work:

for i,v in pairs(Character:GetChildren()) do 
	if (v:IsA("Accessory")) and (v:FindFirstChild("Handle")) then 
		v:Destroy()
	end
end

Oddly enough this did not work.

Boosting post (charlimitfunny)

Try this my friend.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		plr.CharacterAppearanceLoaded:Wait()
		for _, hat in chr:GetDescendants() do
			if hat:IsA("Accessory") then
				hat:Destroy()
			end
		end
	end)
end)
1 Like

You’ve got --local c = character yadda yadda yadda etc, maybe explain exactly what this line says. Does this reference the character in the workspace, in the Players service, or somewhere else?

Where is the script located, and is it a local or server script?

Do you want all player’s hats to be destroyed when they join, or do you just want hats that are located in their backpacks destroyed?

This worked flawlessly, I guess I just forgot to wait for the appearance to load.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.