Interesting! Thank you for knowing that!
In a way, yes.
Though, coroutines are better in most cases as it allows you to control it at any time.
coroutine.resume()
coroutine.yield()
coroutine.create()
coroutine.wrap()
and so on
It is hard to me but I can learn that! Parallel Luau and corountine!
You’re welcome! If you have any more question you can ask me and probably @remcodesremcodes too. Anyway, good luck!
Actually, you can.
function SendToOutputForever(text: string)
while true do
print(text)
end
end
task.spawn(SendToOutputForever, "Hellooooooooooo")
--^^^
--never do this please
i think coroutines are just slightly faster than task.spawn. Correct me if i’m wrong tho.
I need to learn about Task too
Agreed! Here is some more information about task if you want task | Documentation - Roblox Creator Hub
The Task Library is a library of functions.
Every function in this library starts with task.
These functions include:
task.wait()
task.spawn()
task.defer()
task.desynchronize()
task.synchronize()
task.delay()
task.cancel()
The task library is designed to keep the game running smoothly and efficiently.
There is a system named Parallel where scripts can be split into main and side threads.
This allows different parts of your script to run things at the same time allowing for less work to be done on one thread.
This ensures that your game will load each frame faster than normal.
You’re a really smart guy. I wouldn’t doubt if you told me you’ve learned multiple other programming languages. You’re fast, efficient and you explain very well, crazy
Do note that:
task.desynchronize()
and task.synchronize()
can only run under scripts that are a descendant of an Actor. Else, the script would error.
Thread is when you can pass through the script or do not stop other scripts even if there is a while loop for example, am I correct?
That is really good, thank you!
Why is the sound script not working?
for _,v in pairs(script.Parent:GetDescendants()) do
if v.ClassName == "TextButton" then
v:GetPropertyChangedSignal("MaxVisibleGraphemes"):Connect(function()
script.Text:Play()
end)
end
end
Imagine an actual thread . If we were to split it into two using task.desynchronize
or coroutine.create
, we will have… two threads! Okay, that was stupid but you get it.
These threads have their own code and work alongside each other.
If we had one thread running two loops, the first one would run but not the second one. However, if we had one loop on both threads, both loops would run.
while true do
--do something
end --will run
while true do
--do something else
end --will not run
--____________________--
------First Thread------
while true do
--do something
end --will run
-----Second Thread------
while true do
--do something else
end --will also run
I got it!! Also that was a good example not gonna lie XD. So threads makes you able to run multiple tasks at the same time?
That is correct!
Both coroutines and the task library work with threads well.
Thank you guys! You are helping me a lot! I am getting even more knowledges for yall :>. I will learn that, I will learn everything from Lua! Thank you for giving me the start.
Glad we could help you! Remember that you can still have help from others, you don’t need to learn everything yourself.
Thank you :> I will count with you and @Youf_Dev in case I need. If you want, of course XD
Talking about that, how long have you been working with Lua?