Lava script game logic to move and teleport back

Viewed 24

I made this script in my game and its supposed to move a chunk of lava down and then teleport back up when the lava reaches the bottom

Lava Code:

local part = script.Parent
local bottom = workspace.bottom
wait(5)

while wait(0) do
    part.Position -= Vector3.new(0,1,0)
end

function reset(part)
    part.Position = Vector3.new(-100.412, 102.5, -8.321)
end

bottom.Touched:Connect(reset)
1 Answers

So the reason why the lava keeps moving down is because the bottom.Touched will not actually function. This is because of the while loop. The rest of your code never actually gets triggered until the while loop completes which it never will.

local part = script.Parent
local bottom = workspace.bottom
wait(5)

while wait(0) do
    part.Position -= Vector3.new(0,1,0)
end
----------------------------------------------
print("Nothing below will be printed")

function reset(part)
    part.Position = Vector3.new(-100.412, 102.5, -8.321)
end
bottom.Touched:Connect(reset)

In order to fix this, you can move the bottom.Touched connection above the loop

local part = script.Parent
local bottom = workspace.bottom
wait(5)

function reset(part)
    part.Position = Vector3.new(-100.412, 102.5, -8.321)
end
bottom.Touched:Connect(reset)

while wait(0) do
    part.Position -= Vector3.new(0,1,0)
end
Related