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

Removing Accessory on join?

Asked by 7 years ago

I Don/t know why it not removing it, It should work

function onChildAdded(child)
    if child.className == "Accessory" then
        child.Parent = nil
        child:ClearAllChildren()
        child:Destroy()
    end
end 

game.Workspace.ChildAdded:connect(onChildAdded)
wait(300)

local lastcheck = false
while true do
    wait(60)
    local pls = game.Players:GetChildren()
    if #pls == 0 then
        if lastcheck then
            Instance.new("ManualSurfaceJointInstance")
        end
        lastcheck = true
    else
        lastcheck = false
    end
end

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I get mixed messages out of this.

-- || Services ||
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

-- || ChildAdded Destroy ||
Workspace.ChildAdded:connect(function(Item)
if Item:IsA("Accoutrement") then --This'll remove Hats, Accessories and Accoutrements.
Item:Destroy()
end)

-- || Character Accessory Removal ||
Players.PlayerAdded:connect(function(Ply)
    Ply.CharacterAdded:connect(function(Char)
        for i,v in pairs(Char:GetChildren()) do
            if v:IsA("Accoutrement") then
                v:Destroy()
                    end
end)
end)

Logically, as Cabbler mentioned, the loop you gave was unnecessary since there's a lot of functions that could trigger at the time you're probably wanting.

Ad
Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

It should work if you wait(). This only deletes accessories that players want to remove, I hope you know that.

function onChildAdded(child)
    if child:IsA("Accessory") then --this is safer
    --wait so that you do not interrupt the child addition
    wait()
    --you only need one function
        child:Destroy()
    end
end 

workspace.ChildAdded:connect(onChildAdded)

The loop other loop seems really irrelevant and useless.

0
it's in the character it seems killzone45671 -20 — 7y

Answer this question