Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

For some reason :RemoveAccessories not working?

Asked by 5 years ago

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.

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() Donut792 216 — 5y
0
A function doesnt run unless called. DinozCreates 1070 — 5y
0
I'm so stupid you're right thank you. @DinozCreates aoaoaoaoa00 4 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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);
Ad
Log in to vote
-1
Answered by
seith14 206 Moderation Voter
5 years ago
Edited 5 years ago

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

Answer this question