Hey does anyone know how to fix "the Something unexpectedly tried to set the parent of (Skin) to NULL" bug?

hey does anyone know how to fix “the Something unexpectedly tried to set the parent of (Skin) to NULL” bug?

I have a skin shop in my game where if you spam equip then unequip hats it starts to lower fps.

What happens is that the script must check if the player has any accessories, I know that you most likely have them, but that way you do not obtain the accessories of the players, rather do it by going through all the children of the player character and you specifically obtain the accessories and so you eliminate them then you do what you have to do

1 Like

hey I’m a bit confused on how I can go through all the children of the player with the code I’m using right now.

local clone = tool:FindFirstChild(NormalSkin):Clone()
--clone.Parent = Character
-- if snippet doesn't work, you can use the comment above and try if it works.
Character.Humanoid:AddAccessory(clone3)

Correct me if I’m wrong but does this only work on one hat or multiple? (I’m working with multiple hats)

It works for any accessory. What is your problem exactly?

this warning happens because you remove the accessories right when the character was created. to bypass this warning, replace your removeaccessories line with this

for i, v in pairs(Character:GetChildren())
    if v:IsA("Accessory") then game:GetService("Debris"):AddItem(v,0) end
end
  
2 Likes

Like said above, you just need to wait a frame before attempting to remove an instance. In other words, an instance can only be reparented once per frame (because it does not know which one should come first).

2 Likes

You can just call task.wait() (do not pass an argument) before looping through them, you don’t need to use Debris.

task.wait()
for _, child in player.Character:GetChildren() do
    if child:IsA("Accessory") then child:Destroy() end
end
2 Likes

I’m working with multiple hats that are being removed.

So I have a skin shop in the game where if you spam equip and unequip skins it starts to lag the game

1 Like