If I use:

local npcIsHere = true
print("Hello!")
wait(10)
print("Goodbye!")
local npcIsHere = false

And in the event the program doesn't stay for 10 seconds, and goes in 5 seconds instead (after a function is called to set variable npcIsHere to false), how would I go about making this? Any other way I could think of is:

local npcIsHere = true
print("Hello!")
for i = 0, 10 do
    wait(1)
    if npcIsHere == false then
	    break
    end
end
print("Goodbye!")
local npcIsHere = false

But this adds lines and I plan on making the code super small.

4 comments

0

Coroutines.

0

To "cancel" a yield you just need to make sure the yielding function returns. Not exactly sure what you're after here. Perhaps you want to find an event and wait for it?

0

I would like "Goodbye" to be printed when npcIsHere is set to false, but not to be printed when with the function that sets npcIsHere to false.

0

Do not ask subjective questions like "What is the best way", "what is the most efficient way", ect.