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

Hat remover not removing hats, no errors?

function onClicked(playerWhoClicked)
		local playerBody = game.Workspace[playerWhoClicked.Name]
		local d = playerBody.Parent:GetChildren() 
		for i=1, #d do 
			if (d[i].className == "Hat") then 
				d[i]:remove() 
			end 
		end
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

So, I wrote this script that should remove all of a player's hats. It doesn't output any errors, but it doesn't remove the hats.

2 answers

✓ Accepted answer

if this helped, please be sure to accept my answer :) I have left some comments below.

function onClicked(playerWhoClicked)
        local playerBody = game.Workspace[playerWhoClicked.Name] -- or you could just do "playerWhoClicked.Character"
        local d = playerBody:GetChildren() -- You don't need to get the parent, you already have the character.
        for i=1, #d do 
            if (d[i]:IsA("Hat") or d[i]:IsA("Accessory")) then -- "ClassName" is deprecated. You should also find a Accessory.
                d[i]:Destroy() -- remove is deprecated
            end 
        end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments

0

Thanks!

0

Np!

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