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

Accessories won't be destroyed from characters. What's wrong with my script?

Asked by 4 years ago

I'm trying to destroy accessories in characters for a specific team, but the code I'm using isn't working. I get no errors, but accessories still aren't destroyed. Everything else in the script works.

local teams = game:GetService("Teams")
local zomb = teams.Zombie
local zombiestuff = game.ReplicatedStorage.ZombieTeam

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        if plr.Team == zomb then
            local char = plr.Character
            for i,v in pairs(zombiestuff.Regular.Meshes:GetChildren()) do
                v:Clone().Parent = char
            end
            local shirt = char:FindFirstChild("Shirt")
            local pants = char:FindFirstChild("Pants")
            if shirt ~= nil then
                shirt:Destroy()
                zombiestuff.Regular.Shirts.Shirt:Clone().Parent = char
            elseif shirt == nil then
                zombiestuff.Regular.Shirts.Shirt:Clone().Parent = char
            end
            if pants ~= nil then
                pants:Destroy()
                zombiestuff.Regular.Shirts.Pants:Clone().Parent = char
            elseif pants == nil then
                zombiestuff.Regular.Shirts.Pants:Clone().Parent = char
            end
            for i,v in pairs(char:GetChildren()) do --delete accessories
                if v:IsA("Accessory") then
                    v:Destroy()
                end
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
local teams = game:GetService("Teams")
local zomb = teams.Zombie
local zombiestuff = game.ReplicatedStorage.ZombieTeam

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        if plr.Team == zomb then
            local char = plr.Character
            for i,v in pairs(zombiestuff.Regular.Meshes:GetChildren()) do
                v:Clone().Parent = char
            end
            local shirt = char:FindFirstChild("Shirt")
            local pants = char:FindFirstChild("Pants")
            if shirt ~= nil then
                shirt:Destroy()
                zombiestuff.Regular.Shirts.Shirt:Clone().Parent = char
            elseif shirt == nil then
                zombiestuff.Regular.Shirts.Shirt:Clone().Parent = char
            end
            if pants ~= nil then
                pants:Destroy()
                zombiestuff.Regular.Shirts.Pants:Clone().Parent = char
            elseif pants == nil then
                zombiestuff.Regular.Shirts.Pants:Clone().Parent = char
            end
        local d = char:GetChildren() 
            for i=1, #d do 
                if (d[i].className == "Accessory") or (d[i].className == "Hat") then 
                d[i]:remove() 
            end 
        end
        end
    end)
end)

Hope this helps.

Ad

Answer this question