i have these functions: rise(Part), rise(Right) how can i run them at the same time?
You can call functions inside functions (but don’t call function its inside)
local function func1()
--code
end
local function func2()
--code
func1()
end
This wouldn’t run func1 until the end of func2. This is a more proper way of “running two functions at the same time”:
local function func1()
end
local function func2()
end
spawn(func1)
spawn(func2)
Lua is single threaded - the task scheduler (spawn/wait/etc) will run each function sequentially, but never at the same time.
so i would have to make another script , right?
It wouldn’t make a difference, except for creating an extra instance.
If script A runs first then script B must wait for script A to finish completely.
No. All scripts run sequentially - other scripts included. Roblox task switches between each script/thread on events - there is no way of doing what you are asking.
i made the same script twice and then i change the function and it worked.
That’s not what he’s saying. When it comes to Lua (and furthermore Roblox), there cannot at any point ever be two tasks running in exact parallel. Running code in spawn or another script or whatever may seem like it’s running at the same time, but it’s actually not.
Although Lua can only run tasks one by one, you can use coroutine to get the illusion that two functions are running at the same time. This method is efficient, or that’s what it said. Anyways, it’s interesting and should totally be utilized more.
Heres the link to it on the wiki:
If you have two functions that yield, they can be switched between automatically so that one runs while the other is yielded. Running the two functions in separate coroutines (which spawn
does) achieves this. Running the functions in completely separate scripts also does this, only while making a mess.