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

Destroyable gate not disappearing after hp depletion?

Asked by 4 years ago

I've thought about this countless times on ways i could do it but i can't wrap my head around it.I'm trying to make a gate/brick(s) that vanish/destroy to allow you to then walk through the destroyed part.It's somewhat like the gate(s) from "Medieval warfare reforged".I've added a humanoid "torso","head" to the brick but I don't know how to remove the piece completely.Any idea why the code isn't working?

function waitForChild(parent, childName)
    while true do
        local child = parent:findFirstChild(childName)
        if child then
            return child
        end
        parent.ChildAdded:wait()
    end
end

-- declarations

local Figure = script.Parent
local Head = waitForChild(Figure, "Head")
local Humanoid = waitForChild(Figure, "Humanoid")
Humanoid.Health=600
-- regeneration
while true do
    local s = wait(4)
    local health = Humanoid.Health
    if health > 0 and health < Humanoid.MaxHealth then
        health = health + 0.01 * s * Humanoid.MaxHealth
        if health * 1.05 < Humanoid.MaxHealth then
            Humanoid.Health = health
        else
            Humanoid.Health = Humanoid.MaxHealth
        end
    end
end

1 answer

Log in to vote
0
Answered by 4 years ago

Add a Died event so when the humanoid's health is 0 it fires removing the gate

function waitForChild(parent, childName)
    while true do
        local child = parent:findFirstChild(childName)
        if child then
            return child
        end
        parent.ChildAdded:wait()
    end
end

-- declarations

local Figure = script.Parent
local Head = waitForChild(Figure, "Head")
local Humanoid = waitForChild(Figure, "Humanoid")
Humanoid.Health=600
-- regeneration
while true do
    local s = wait(4)
    local health = Humanoid.Health
    if health > 0 and health < Humanoid.MaxHealth then
        health = health + 0.01 * s * Humanoid.MaxHealth
        if health * 1.05 < Humanoid.MaxHealth then
            Humanoid.Health = health
        else
            Humanoid.Health = Humanoid.MaxHealth
        end
    end
end
Humanoid.Died:Connect(function() -- connect died function
Figure:Destroy() -- you can add destroy effects

end)
Ad

Answer this question