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

How to delete Accessory, Shirt, Pants, Body Colors, T-Shirt on player when it spawn to workspace?

Asked by 7 years ago

How to delete Accessory, Shirt, Pants, Body Colors, T-Shirt on player when it spawn to workspace?

local ClassName = { "Accessory", "Shirt", "Pants", "Body Colors", "T-Shirt" }

workspace.ChildAdded:connect(function(object)
    local NewPlayer = game.Players:playerFromCharacter(object)
    if NewPlayer ~= nil then
        for index, value in pairs(object:GetChildren()) do
            if value:IsA(ClassName) then        
                value:Destroy()
            end
        end
    end
end)
0
You can use the :ClearCharacterAppearance() method of Players Tkdriverx 514 — 7y

1 answer

Log in to vote
-1
Answered by
RGRage 45
7 years ago

Use the PlayerAdded event to get the player that has just joined and then use the CharacterAdded event to get the character of that player

Here is what your script should look like:

local ClassName = { "Accessory", "Shirt", "Pants", "BodyColors", "Shirt" }

game.Players.PlayerAdded:connect(function(player) -- Use the PlayerAdded to get the player that has just been added

    player.CharacterAdded:connect(function(character) -- Use the CharacterAdded event to get the character of 'player'

        wait(2) -- Add a wait just in case that player objects have not loaded yet

        for _,obj in pairs(character:GetChildren()) do -- Loops through each object of the character and returns the value

            for i, CN in pairs(ClassName) do -- loops through the class names and returns the value of each

                if obj:IsA(CN) then -- checks to see if the objects class name is the value of the Class Name in the array defined before

                    obj:Destroy()

                end
            end
        end
    end)
end)
Ad

Answer this question