Back Accessory Remover not working

So im making a game with Swords, and i want them Displayed on the back of the Player, before they are equipped. Now for that i was Planning on using a small script which searches for back Accessories and removes them. Now in my case, im thinking that code should work perfectly fine, but it isn’t removing anything (no errors etc)? Am i missing something or could the script as itself not work ( Script is in starter character scripts)

local character = script.Parent

for i, child in pairs(character:GetChildren()) do
	if child:IsA("Accessory") then
	warn("Found: "..child.Name, i)
	if child.AccessoryType == Enum.AccessoryType.Back then
		child:Destroy()
		warn("Removed: "..child.Name,i)
	else return end
	
	end
end
1 Like

Remove this line and add 1 more end:

else return end

Like this:

local character = script.Parent

for i, child in pairs(character:GetChildren()) do
	if child:IsA("Accessory") then
	warn("Found: "..child.Name, i)
	if child.AccessoryType == Enum.AccessoryType.Back then
		child:Destroy()
		warn("Removed: "..child.Name,i)
    
	  end
	end
end

thanks, i overthought that, but it still does not seem to work

Where this script located?

As already mentioned, the script is located in: StarterPlayer → StarterCharacterScripts

Oh, sorry, i didn’t see. Then try to use this to character:

local character = script.Parent.Parent

That does still not work, since its now getting the Workspace

i might have found what could be the problem. Uppon printing everything thats being found; here is what i have discovered:
image

its not even finding the Accesories

Try to use this for warn:

warn("Found: "..child.Name .. i)

Wait a sec, it is local script?

Yeah it is. I have just realized. It should still not make a Big impact tho, seeing the Local player (should) not see their back accessories

Even tho, uppon changing it to a normal script, it also listed the Animator, such as the health script, but nothing more, no Accesories were named

local character = script.Parent

for i, child in pairs(character:GetChildren()) do
    if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Back then
        child:Destroy()
        warn("Removed: "..child.Name)
    end
end

It looks a bit cleaner, but still sadly does not work

Hey Lenni!

I think the issue is that the character hasn’t completely loaded when the script executes.

Try this:

local Players = game:GetService("Players")

local character = script.Parent
local player = Players:GetPlayerFromCharacter(character)

player.CharacterAppearanceLoaded:Wait()

for i, child in pairs(character:GetChildren()) do
    if child:IsA("Accessory") and child.AccessoryType == Enum.AccessoryType.Back then
        child:Destroy()
        warn("Removed: "..child.Name)
    end
end

This code waits for the character’s appearance to load before executing the for loop.

Hope this helps!

2 Likes

OH Thank you for your answer, i have not thought of that yet. Uppon reading that i realized i overthought a little. The minor things can cause Huge things. Thanks for your helpful reply

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.