Basically, when a player clicks their mouse button, while ‘CanCatch’ is true, it sets ‘Catching’ to true. However, they have to wait the 3 seconds before the code continues.
-- Random wait for fish to appear
while not Catching do
local RandomWait = math.random(3, 7)
wait(RandomWait)
print('Allowed to catch')
CanCatch = true
wait(3)
CanCatch = false
end
print('Player is catching fish!')
So how can I quickly break this without doing something like this
if Catching then break end
wait(0.5)
if Catching then break end
wait(0.5)
if Catching then break end
wait(0.5)
if Catching then break end
wait(0.5)
if Catching then break end
wait(0.5)
if Catching then break end
wait(0.5)
Using wait() is not recommended, but you can use repeat loop to achieve it:
local start_tick = tick()
repeat wait() until Catching or tick() > start_tick + 3
if Catching then break end
You can use RunService.RenderStepped:Wait() if this is something rendering-related.
Or RunService.Heartbeat:Wait() if this is something not-so-related-with-rendering.