Hello i write a script which waits for a while. i didnt use wait() cuz i wanna stop the loop whenever a button pressed or time passes.

The problem is you need to press the button to activate the script. And repeat loop (this loop is inside the script) takes button press for activate script for finish himself. How can i solve this?

local randomwait = math.random(10, 100)
local breakloop2 = 1
local breakloop3 = false
local getquestion = gui.GetQuestion
			
repeat
	wait(0.1)
	breakloop2 = breakloop2 + 1
until breakloop2 == randomwait or  getquestion.MouseButtonClick 

if breakloop2 == randomwait then
	breakloop1 = false
else
	breakloop1 = true
end

2 comments

0

Where is breakloop1 its never defined

0

probably earlier in the script