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

Why Is This Simple Delete Hats Script Not Working?

I'm trying to delete the player hats when the player spawns. Everything seems fine in the code, but it's not deleting my hats.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		for _, child in ipairs(character:GetChildren()) do
		    if child.ClassName == "Accessory" then
		        child:Destroy()
		    end
		end
	end)
end)

*Updated to child:Destoy() but it still does not work

2 comments

1

On line 5 change child.Destroy() to child:Destroy() with a colon instead of a period.

0

You can use a period, he just needs to put child between the brackets if you use a period. :Destroy() is syntax sugar for .Destroy(child)

2 answers

✓ Accepted answer

You have it right... But, because the hair is added after the fact you must wait for it to be added. Do this...

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        wait(0.5)
		for _,v in ipairs(character:GetChildren()) do
			print(v.Name)
            if v.ClassName == "Accessory" then
                v:Destroy()
            end
        end
    end)
end)

just do

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character.Humanoid:RemoveAccessories()
end)
end)

honestly idk if this is gonna work. I saw the removeaccessories function a while ago and i just never got around to actually trying it.

1 comment

0

if you add wait() between line 2 and 3 then it works

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