Is it possible to see of a function is activate during wait()?

Hi, so basically I want to see if a function is fired (for example: mouse clicked) how can I detect that during the wait?

wait(1) -- During this time, I need to detect if something was clicked, then I can change a variable
if var == false then
return

Is this possible?

I’d recommend you use task.delay()

local var -- This is your variable
task.delay(1, function()
    if var == false then
        -- Var is false
    else
        -- Var is true or nil
end)

This will execute the function after the delay ends, in this case 1 second.

Ah but basically I’m using this

task.spawn(function()
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
--something happens
wait(0.1)
end)

wait(1) -- this is the task wait time
--but, when the task is progressed I want to see if a button is clicked, then I can change the
--variable.

But I dont know how to see if it’s clicked

You can use the coroutine library, and I cannot understand why you use a lot of wait. Even easier, instead of using the coroutine library, print when the MouseButton1Click event is done.

1 Like

And to what you try to do:

task.spawn(function(...)
	while task.wait(TIME) do
		-- something happen
		print "occurred"
	end
end)
1 Like