Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make this loops stop right when the character moves?

function meditation(moving,equipped)
	 while moving == false and equipped do
			progress.Size = UDim2.new(0,0,1,-4)
			progress:TweenSize(UDim2.new(1, -4, 1, -4),"Out","Linear",10,false)
			if equipped == false or moving == true then
				frame.Visible = false
				break
			end
			wait(10)
			updateMagic:FireServer(orbSize)	
	end
end

function moveDetect(speed)
	if equipped then
		if speed > 5 then
			moving = true
			meditating = false
			print("moving")
		else
			moving = false
			print("stoppedmoving")
		end
	end
end

The problem here is

if equipped == false or moving == true then
		frame.Visible = false
		break
end

only checks once so if moving = false while it checks once then during the 10second wait if moving turns true, it doesn't break the loop. How can i make it so that as soon as the char moves the while loop breaks?

2 comments

0

Can you show the code for the variables?

0

Use a while loop to keep checking and then break it when equipped is falsse or moving is true.

1 answer

This might work:

while true do
	if not equipped or moving == true then
        	frame.Visible = false
        	break
	end
	wait(0.1) -- Cooldown so it doesn't crash
end

This discussion is preserved as it was. New answers, comments, and votes are closed.