Click here to Skip to main content
14,699,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm building a game using Lua, including the built-in functions Roblox provides. However, this question isn't Roblox specific = I think it can apply to anything using Lua language. However, just be aware that the solution can involve Roblox-Built-In functions. So I have a script, however, I need it to wait until one of my values is equal to 1. It's like a flag. While I'm familiar with the wait() function that allows one to pause the script for several seconds, I'm not sure how to do something like "Wait until Flag.Value = 1". I have a local function I wish to run, but only when the Flag's value is equal to 1.

What I have tried:

I've already tried a few approaches, such as using a while true loop. I wrote something like this:

while true do
if Flag.Value = 1 do

However, this returns an error: "Script timeout: Exhausted allowed execution time". I'm not sure if this error is related, but when I got rid of my loop and just called the function, there was no error. Is there a way to do a statement like "wait until"? Thanks
Updated 21-Aug-20 23:07pm

1 solution

The problem is that the execution takes too long, and Roblox assumes that you app has crashed and died - so it kills it for you. Your while loop sits there checking the flag over and over and doing nothing else, so the assumptuion is it's never going to exit.

Have a look here: How to handle "Script timeout: exhausted allowed execution time" - Scripting Support - Roblox Developer Forum[^] - it may explain it better, and it shows what you probably need to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900