Instead of using a for loop or something similar, is there an easier (maybe built-in) way to go past the wait?
-- code wait(1000) -- i want to skip this wait -- code
use coroutines or spawn. they make a new thread (spawn has a 1/30th of a second delay but is less complicated than coroutines.) this allows you to have multiple blocks of code running at the same time.
for example:
spawn(function(a) --//spawn requires a function to execute. not a function call, but the function variable itself. wait(5) print('I called this function in another thread after 5 seconds.') end) wait(1) print('I called this function in the main thread after 1 second.')
and then there's coroutine. nobody likes coroutine. there are multiple ways to run coroutine.
number 1: there is coroutine.create and coroutine.resume. resume takes the created coroutine and executes--it is a variadic function, meaning it can take an endless amount of variables. take note that it's like calling a method but using a dot, kind of. it requires the coroutine that you wish to call as a first argument. the variadic comes after that.
local Coroutine = coroutine.create(function(x,y,z) print(x^2+y^2 == z^2) end); coroutine.resume(Coroutine, 15, 15, 450) --// returns true or false depending if your arguments follow the pythagorean theorem
number 2: there is coroutine.wrap. it's like calling a function. but with a coroutine. it's weird, i know.
local Coroutine = coroutine.wrap(function(x,y,z) print(x^2+y^2 == z^2) end); Coroutine(15, 15, 450) --//same as above, really.
beginner's guide to coroutine and spawn.