Click here to Skip to main content
15,890,741 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
examplefunction()
end
end

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
Posted
Updated 29-Jan-21 18:25pm

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.
 
Share this answer
 
while Flag.Value == 1 do
-- your stuff
wait(0.15)
end

oh yeah it's because you are executing the function to fast, maybe add a wait() function after that like the one I did.
 
Share this answer
 
v3

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