How do I remove a player his accessory?

Hello,

I got this problem that I make the player invisible but you are still able to see his accessory how do I remove them or make them transparent too?

(Video)

  • Vosken

You could use a pairs loop to loop through the player and find the accessories, and if they do have accessories then they get removed/ moved. An easy example of how to do this is so:

for index, value in pairs(Player_Here.Character:GetChildren()) do

   if v:IsA("Accessory") then
      v.Parent = Folder_Here
   end

end
1 Like

Yes but how would I know the player “Player_Here” ?

Because you just made them invisible?

Ye with a spell not using a command

Its not that I write there names down its for a game

You could simply do Torso.Parent:GetChildren() or Character:GetChildren() if you just define it.

My scripting is pretty bad xD, Could you write the line for me? would save some time

I am more like a builder but my game needs scripts too so I do my best

for index, value in pairs(Torso.Parent:GetChildren()) do

   if value:IsA("Accessory") then
      value.Parent = Folder_Here
   end

end

The “v” is underlined for me what do I do xD

Simple way to remove all accessories:

local char = game.Players.LocalPlayer.Character
for i,v in pairs(char:children()) do
    if v:IsA("Accessory") then
        v:Destroy()
    end
end

thank me later
(assuming its in a localscript and if the Parent is the player simply do script.Parent.Character)

@Benified4Life’s code is meant to say:

if value:IsA("Accessory") then
    value.Parent = Folder_Here
end

I believe he accidentally wrote “v” rather than “value” because (like in @Enderxcthz’s code) the for loop is usually written as for i,v in pairs() rather than for index,value in pairs()

2 Likes

Ah heck, forgot about that! Thanks for the edit.

1 Like

Tyvm, That made it work do you happen to know how to remove the face aswell (Not really needed but would make it look better)

1 Like

Try using what the engine provides you over reinventing the wheel. Humanoids have a method called RemoveAccessories. This is functionally equivalent to getting the children of the character, class-checking the child in the current iteration and then destroying it, just all of this is done in one function.

In your spell function, above or below all the transparency modifications, place in Humanoid:RemoveAccessories() and all the character’s accessories will be removed.

1 Like

To hide the face, you can simply set the face decal’s transparency to 1. Later on if you want to make the character visible again, you would set the transparency back to 0.

You can find the face decal by looking through the character’s hierarchy (it’s in the Head part) and change it from there in the script.

Thank you it works aswell :+1:

1 Like