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

How can I delete the character's accessories from the character?

This script is made to override the character and delete the player's accessories. Here's my code:

local player = game.Players:GetPlayerFromCharacter(script.Parent)
local character = player.Character
local character_children = character:GetChildren()

--:ClearCharacterAppearance()
character:WaitForChild("ForceField")
character.ForceField:Destroy()
local hats = character:FindFirstChildWhichIsA("Accessory")
hats:Destroy()						--This is where I want to remove the hats, which it doesn't
character.Head.Transparency = 1
character.Torso.Transparency = 1
character["Left Arm"].Transparency = 1
character["Right Arm"].Transparency = 1
character["Left Leg"].Transparency = 1
character["Right Leg"].Transparency = 1
character.Sound:Destroy()
character.Head.face:Destroy()
character.Humanoid.JumpPower = 0
character.Humanoid.CameraOffset = Vector3.new(0, 10, 0)

The code's hierarchy

I tried this: game.Players.LocalPlayer:ClearCharacterAppearance() and it doesn't get rid of the accessories.

What do I do!?

2 comments

0

why u gave me a min??? i just gave u a exaple how to find them

0

Learn how to use loops, it'll definitely optimise your scripts and help you in the long run.

4 answers

Looking at the code's hierarchy, it looks like this is being done inside a LocalScript. If you intend the accessories to be deleted across every player's game, then using a regular server Script will be the way to go.

Anyway, to answer your question, I have gone into studio and cleaned up your script. Basically, it searches the character and deletes any accessory or face, then changes all the parts in the character to become invisible.

wait(1/2)

local char = script.Parent
local characterPart = script.Parent:GetDescendants()

for a = 1, #characterPart do
	if characterPart[a]:IsA("BasePart") then
		characterPart[a].Transparency = 1
	elseif characterPart[a]:IsA("Accessory") or characterPart[a].ClassName == "Decal" then
		characterPart[a]:Destroy()
	end
end

char.Sound:Destroy()

Or you can ignore all that and instead go to StarterPlayer.LoadCharacterAppearance and set it to false.

1 comment

0

not every thing is a base part, look my script with tele porting. i looked at my own character for that when i tested it in workspace

There is a function in Humanoid called RemoveAccessories()

player.Character.Humanoid:RemoveAccessories() -- Will remove all accessories the player has equipped.

I hope this helps!

local player = game.Players:GetPlayerFromCharacter(script.Parent)
local character = player.Character
local character_children = character:GetChildren()

for i,v in pairs(character_children) do
if v:IsA("Accessory") then
v:Destroy()
end
end

and then add the other things of ur script into this

1 comment

0

this will look into the characters children and delete every accessory

i have it like this in my teleport service to transparence the parts but u can say when found part:destroy() to destroy them or with part.Parent = place to move them or with local copy = part :Clone() to clone them and then copy.Parent = placetomove to move the copy

			for _, part in pairs(player.Character:GetChildren()) do
    				--for each of the objects in the character,

       				if part:IsA("MeshPart") or part:IsA("BasePart") or part == "Head" then
        				--check if it's a part, and if so
						if part.Name ~= "HumanoidRootPart"then
							part.Transparency = transparency
						else
							part.Transparency = 1
						end
          			  
           			 	--set its transparency
        			end

					if part:IsA("Accessory") then  --<-- this part u looking for
						for _, part in pairs(part:GetChildren()) do
							if part:IsA("Part") then
								part.Transparency = transparency
							end
						end
					end
   				end

1 comment

0

i have a function in my teleport service that make the parts changer 0.1 transparency every 0.1 sec. so thats why there is : part.Transparency = transparency. so it go up and down with teleporting first 0.1 every 0.1 sec + then poof teleport then every 0.1 sec -0.1 

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