Hello, I am trying to delete a character’s accessory items when they join the game, along with that I destroy all items that are character meshes and set body color.
As you can see I am using the same code to delete character meshes (which works) and character accessories (which doesn’t work yet its the same code?).
It finds and deletes all objects in the character’s model that are “CharacterMesh” but not all objects that are of the class “Accessory” (I checked if I spelled it right multiple times and for other mistakes).
When I run the script I do NOT get any errors, which is weird, since its not actually deleting any accessories. Usually it would say that the class doesn’t exist or some other error.
In game as you can see in my player model, accessories do exist in the model:
And every time I run the game all runs “fine” but my player still has accessories on:
Does anyone know what I am doing wrong and how to make the script work, thanks
game.Players.PlayerAdded:connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
for i,v in pairs (character:GetChildren()) do
if v:IsA("Accessory") then
v:Destroy()
end
end
end)
Well, I used the script that you provided above for character mesh also and it works perfectly fine for character mesh but not for accessories. So your script above was correct its just that for some reason its not removing player accessories.
Edit: With the script I already have, it does find the player’s character model fine, so it’s not that causing it not to work.
Also, just to make clear that I am using your code in the script that is working, so the script IS running, but for some reason not removing my accessories.
game.Players.PlayerAdded:Connect(function(play) play.CharacterAdded:Connect(function(char) for _,v in pairs(char:GetChildren()) do if v:IsA("Accessory") then v:Destroy() end end end) end)
It looks like accessories are being added after your code is executed. Try something like this within your character added function:
local function check(instance)
if instance:IsA("Accessory") or instance:IsA("CharacterMesh") then
instance:Destroy()
end
end
for _, v in pairs(character:GetChildren()) do
check(v)
end
character.ChildAdded:Connect(check)