#lava keeps rising even tho i hit 0 Health when i need it to stop

5 messages · Page 1 of 1 (latest)

dire nexus
#

im kind of new to coding and cant seem to figure this out, i want it so when my health reaches 0 (dies) the lava stops moving up, but instead it keeps on moving

local distance = 0
local enabled = true
local originalPosition = game.Workspace.Lava.CFrame

game.Workspace.Lava.Touched:Connect(function(PlayerWhoTouched)
    if enabled then
        local character = PlayerWhoTouched.Parent
        local humanoid = character and character:FindFirstChild("Humanoid")
        if PlayerWhoTouched.Name == "LeftFoot" or PlayerWhoTouched.Name == "RightFoot" then
            if humanoid then
                humanoid.Health = 0
                enabled = false
                wait(1)
                game.Workspace.Lava.CFrame = originalPosition
            end
        end
    end
end)

script.Parent.MouseButton1Click:Connect(function()
    distance = 1000
    if enabled == true then
        for i = 0, distance do
            wait(0.001)
            game.Workspace.Lava.CFrame = game.Workspace.Lava.CFrame + Vector3.new(0, 0.1, 0)
            wait()
        end
    end
end)

what is wrong with it?

fathom pilot
#
local distance = 0
local enabled = true
local originalPosition = game.Workspace.Lava.CFrame

game.Workspace.Lava.Touched:Connect(function(PlayerWhoTouched)
    if enabled then
        local character = PlayerWhoTouched.Parent
        local humanoid = character and character:FindFirstChild("Humanoid")
        if PlayerWhoTouched.Name == "LeftFoot" or PlayerWhoTouched.Name == "RightFoot" then
            if humanoid then
                humanoid.Health = 0
                enabled = false
                wait(1)
                game.Workspace.Lava.CFrame = originalPosition
            end
        end
    end
end)

script.Parent.MouseButton1Click:Connect(function()
    distance = 1000
    if enabled == true then
        for i = 0, distance do
            if enabled == false then
              return
            end
            wait(0.001)
            game.Workspace.Lava.CFrame = game.Workspace.Lava.CFrame + Vector3.new(0, 0.1, 0)
            wait()
        end
    end
end)
#

That should fix it

dire nexus
#

bro thank you so much, i have no idea how i didn't see that fix😫

#

thanks again