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

Why Does This Only Work Partialy?

Asked by 9 years ago

I am trying to make it so when a player dies, they turn into 50 small bricks. The script clears all the body parts, but does not create any parts. My Script

debounce = false
while true do
    if script.Parent.Humanoid.Health == 0 and debounce == false then
        debounce = true

        local pos = script.Parent:FindFirstChild("Torso").Position
        local child = script.Parent:ClearAllChildren()

        local model = Instance.new("Model")
        model.Name = "temp"
        model.Parent = script.Parent


        for i=1, 50, 1 do
            local b = Instance.new("Part")
            b.BrickColor = BrickColor.new(1012)
            b.Reflectance = 1
            b.Transparency = 0.7
            b.CanCollide = false
            b.Size = Vector3.new(1,1,1)
            b.TopSurface = Enum.SurfaceType.Smooth
            b.BottomSurface = Enum.SurfaceType.Smooth
            b.Position = pos
            b.Parent = model
            wait(0.01)
        end

        wait(2)

        model:ClearAllChildren()

    end
    wait()
end

it is in the players character.

1 answer

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

It's because you deleted the script in line 7. Have the script check what its deleting before it deletes it.

debounce = false
while true do
    if script.Parent.Humanoid.Health == 0 and debounce == false then
        debounce = true

        local pos = script.Parent:FindFirstChild("Torso").Position
        for _,v in pairs(script.Parent:GetChildren()) do --Loop through all objects of the parent.
             if v ~= script then --If the object isn't the script, then continue on.
                   v:Destroy() --Destroy the part.
             end
       end

        local model = Instance.new("Model")
        model.Name = "temp"
        model.Parent = script.Parent

        for i=1, 50, 1 do
            local b = Instance.new("Part")
            b.BrickColor = BrickColor.new(1012)
            b.Reflectance = 1
            b.Transparency = 0.7
            b.CanCollide = false
            b.Size = Vector3.new(1,1,1)
            b.TopSurface = Enum.SurfaceType.Smooth
            b.BottomSurface = Enum.SurfaceType.Smooth
            b.Position = pos
            b.Parent = model
            wait(0.01)
        end

        wait(2)

        model:ClearAllChildren()

    end
    wait()
end

Hope this helps!

0
Thanks and it did help but i ditched the loop and just used a repeat wait() until script.Parent.Health == 0 freerobux456 0 — 9y
Ad

Answer this question