Can a while loop time change when using a value for it?

So let’s say i have a while task.wait loop but I’m using 2 different value, First value is the Minimum time and the Second value is the Maximum time. What I’m trying to do is making a random timer while loop with the 2 value above. The question, If the while loop is still running and i have a script that change the maximum time will the while loop script still use the old max time or the new one? Like i mean before it reach the max time and will the code trigger if its already below the decreased max time?

you can do something like this

local timeValues = {}

while task.wait(timeValues[math.random(#timeValues)]) do
---
end

Edit: if the maximum time changes, it uses the new time value and not old time value.

3 Likes

Will using a number value also work?

Yep

1 Like

Wait if i decrease the maximum time value and the timer is already above the changed maximum value will it automatically start the event/code?

no, it will first complete the loop, then wait for the new maximum time value, and run the code again.

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