Need help with while loop

Hello everyone!

I am trying to create a while loops that makes a part rise. For example in “The floor is lava”.
I already got a part of the script but I don’t know how I could make the part stop rising.

This is the script:

while true do
			Water.Position = Water.Position + Vector3.new(0,.03,0) 
			wait()
end

The water is the part that has to rise.

Anyone knows how to fix this?
Any help is appreciated!

1 Like

You could create a bool variable, and make it the protagonist of the while.

local Bool = true
while Bool == true do
			Water.Position = Water.Position + Vector3.new(0,.03,0) 
            if "The floor is lava" == false then
               Bool = false
            end
			wait(0.1)
end

This is just an example.
Replace the “The floor is lava” with whatever thing it has to check to know if it is lava or not

1 Like

And how can I make the lava stop on a certain position?

Hello,
I would just check part’s position in world. Like, here’s example:

local Water = workspace.Part; -- your water 

local MaxRange = 5; -- how many studs you want to go up

while(true)do --loop
	if(Water.Position.Y >= MaxRange)then -- checking if position of part's above or equal to MaxRange (5 studs)
		print("Lava reached max"); --if yes then loops break
		break;
	end
	Water.Position = Water.Position + Vector3.new(0,.03,0); -- else, part keep going up
	task.wait();
end

I hope this helps.

1 Like

Thank you! This helped!

And thank you for everyone helping!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.