Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Needing help on how to fix this code to delete accessory's and the face?

Asked by 6 years ago
Edited 6 years ago
for _, item in pairs (character:GetChildren()) do
    print("start")
    if item.ClassName == "Part" then
        item.Transparency = 1
    elseif item.Name == "Head" then
        item:FindFirstChild("face"):Destroy()
    elseif item.ClassName == "Accessory" then
        print("accessory")
        item:Destroy()
    end
end

this code deletes the body parts but doesn't delete the face or the accessory's on the player, the body type is R6 and i was wondering if anybody could fix the code so it deletes the players face and accessory's which will basically make the player invisible. I have also tried to use some of the 'fixes' found on this site but they don't work, the script is a local script in StarterCharacterScripts, also please note that "accessory's" does not print.

2 answers

Log in to vote
0
Answered by 6 years ago

Since it’s under StarterCharacterScripts, we can access the Character using script.Parent.

wait()
script.Parent.Humanoid:RemoveAccessories()

script.Parent.Head:FindFirstChildOfClass("Decal"):Destroy()

No for loop needed to remove the accessories.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I had this problem recently. I'm not entirely sure why, but it's a good idea to delete the face of the character (and, though untested, likely accessories as well) through the server and not a LocalScript. Then within a LocalScript, if you want to include a new face/accessories, it should be fine to create them locally.

Answer this question