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
Coroutines.
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?
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.
Do not ask subjective questions like "What is the best way", "what is the most efficient way", ect.