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

How to destroy my characters Torso?

Asked by 1 year ago

How do I destroy my characters Torso in a more complicated way? Serious answers please, this is for science.

--We begin by declaring a variable to store the character’s torso
local torso = game.Players.LocalPlayer.Character.Torso 

--We then define a function which will be responsible for the actual deletion of the torso
function deleteTorso()
    --We start by checking if the torso exists
    if torso then
        --We then use a for loop to loop through all the children of the torso
        for _, child in pairs(torso:GetChildren()) do
            --We check if the child is a Part or a Mesh
            if child:IsA("Part") or child:IsA("Mesh") then
                --If it is, we set its Parent to nil
                child.Parent = nil
            end
        end
        --We then use a recursive function to delete all descendants of the torso
        function deleteDescendants(parent)
            --We start by checking if the parent exists
            if parent then
                --We then use a for loop to loop through all the children of the parent
                for _, child in pairs(parent:GetChildren()) do
                    --If the child is a Part or a Mesh we set its Parent to nil
                    if child:IsA("Part") or child:IsA("Mesh") then
                        child.Parent = nil
                    end
                    --We then call the recursive function on the child
                    deleteDescendants(child)
                end
            end
        end
        --We call the recursive function on the torso
        deleteDescendants(torso)
        --We then set the torso’s Parent to nil
        torso.Parent = nil
    end
end

--We then call the deleteTorso() function
deleteTorso()
0
Why don't you just use if torso then torso:Destroy() end Dadeyom 0 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

ummm why dont you just

torso:Destroy()

i dont get your reason

Ad

Answer this question