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

For some reason :RemoveAccessories not working?

Might've done the coding wrong, but this is what I did.

-- remove hats and accessories

local Players = game:GetService("Players")
 
local function playerAdded(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		
		humanoid:RemoveAccessories()
		
		
 end)
 end

This is a LocalScript inside StarterGui in case the placement was wrong.

Thank you all in advance.

3 comments

0

there is probably an easier way but you could do something like for i,v in pairs(character) do if v.Class == Accessory then v:Destroy()

0

A function doesnt run unless called.

0

I'm so stupid you're right thank you. @DinozCreates

2 answers

You have 2 problems. The first is you have forgotten to connect your function (playerAdded) (Line 5), to the PlayerAdded function of the Players Service.

The second problem is that you have made this a LocalScript in the StarterGui. Because this script is replicated to the client AFTER the player joins the game, the PlayerAdded event will not fire for them. Instead, you can put this in a regular script in any place they run (workspace, ServerScriptService, etc.), and it will work as intended.

There is nothing wrong with the RemoveAccessories() function of humanoids.

Revised script:

-- remove hats and accessories

local Players = game:GetService("Players")

local function playerAdded(player)
    player.CharacterAppearanceLoaded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        humanoid:RemoveAccessories()


 end)
 end

Players.PlayerAdded:Connect(playerAdded);

You forgot to run the function playeradded

local Players = game:GetService("Players")

game.Players.PlayerAdded:Connect(function (player) -- Forgot to run the function
    player.CharacterAppearanceLoaded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")

        humanoid:RemoveAccessories()


 end)
 end

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