This Function Will Save You Hours
HTML-код
- Опубликовано: 10 сен 2024
- 50% OFF COUPON WITH "DOUBLEBYTE" (ends in 3 days):
linktr.ee/Byte...
To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/...
You’ll also get 20% off an annual premium subscription!
discord: / discord
wondered how to make a main menu in roblox studio? or how to create a shop which has working GUI? ive made lots of 2024 roblox scripting tutorials about all the different bits of roblox to give you some up-to-date information about all of its properties and events.
my goal is to simply give some insight on how to use the various features and instances roblox studio, and show you some fun stuff you can do with them. thanks for checking out this roblox scripting tutorial :)
Get all of my knowledge in one package: linktr.ee/ByteBlox
W
Bigger
is he going to mail me a pipebomb?
@@ArtucoDev no but i will
Dear byteblox you probably aren’t seeing this message but I can’t send it in the discord since I was banned. I’d like to appeal my ban, I’m sorry for my beliefs causing others to fell uncomfortable I should of asked you if it was ok for me to state my beliefs. I assumed you could because other people in the server where and I stated mine. Although I do want to say I don’t appreciate people calling me stupid because of my personal opinions my beliefs may seem stupid to them but there’s also seems stupid to me. I also don’t like how my opinions that don’t have anything to do with the server can get me banned.
task.synchronize and task.desynchronize are only to be used with multi threading under actors. If this is not done, then the function will still work, but will warn something along the lines of this: "task.synchronize/task.desynchronize should only be called from a script that is a descendant of an Actor"
both task and coroutines are nearly the same thing, except with a few minor differences. *Note that task.spawn() is slightly slower than coroutine.create()*
task.spawn() can resume "dead" threads, unlike coroutine.resume()
task.spawn() has a debug trace back, unlike coroutines. This basically means that if the script gets an error, it will show where the error occurred inside of the actual function, rather than coroutines which say something about where the coroutine was actually ran.
task.cancel() doesn't return the thread's state, until coroutine.close()
task is better for everyday things, because it is very easy to use.
coroutines are more complicated, and are better for multi tasking programs
overall however, unless you need to get very technical, using either task.spawn() or coroutine.wrap() is fine.
4:12. The reason why you dont use the brackets here is because you are not calling the function but are passing it as a parameter. If you use the brackets then you are not giving the task.spawn a function. Functions typically work as any other data type in lua. You could write a function like this:
local add = function(num1,num2)
return num1 + num2
end
If you use typeof() on a function it will return function. That is what task.spawn does to check if you're sending it a function. If you put the brackets then you will be running the function instead of passing it meaning that the typeof will not recognise the parameter as a function therefore giving you that error
Right you’d be sending in whatever the function returns with the brackets, spawn(Func()) would be like running spawn(nil)
you didn't use task.wait()... you better sleep with all holes closed tonight.
WHAT 💀
wdym “all holes”?
oh my
Lmaoooo
Can I keep *SOME* holes open atleast.?
😩
dude you are literally exactly what i've been looking for thank you for existing
check his woman tutorial it's even better
@@mistasilly fr it helped tons i watched the whoel thing
Mediocrity
Fr
I think you can make a variable and then run a task.spawn(), like
local newThread = task.spawn(SomeFunction: function)
which will return a thread, and then you can make it cancel (stop the thread)
task.cancel(newThread)
correct
Think you could do the same with coroutines
you can
You can also do the same with events.
local connection = BindableEvent.Fired:Connect(...)
connection:Disconnect()
This is exactly what I was thinking when he didn't know how to access threads
That's CRAZY. Are you saying I never had the issue of needing to do something for all elements at the same time, but I always thought to myself it would happen someday and I wouldn't be able to fix it. This is just perfect!
You’re literally the roblox version of khan academy thanks so much bro
i am not joking, this actually saved me from making multiple scripts. thank you so much
you really triggered me when you wrote wait(2) over task.wait(2)
everything else is good though, nice tutorial
I could teach you some of the task functions, I specialise in multi threaded luau
i believe, not too sure but sure since I haven't used roblox studio in a while, task.spawn and task.delay returns a thread which you can use task.cancel on
what's the difference?
I prefer wait()
@@theofficialwoohoogamers task.wait() is more updated and optimised, that's really the whole point of the task library.
you could use spawn() which is deprecated in favour of task.spawn() as well as the other functions
@@theofficialwoohoogamerswait() being deprecated, running at 30 hz, throttling and stuff
@@anto_fire8534oh
@@theofficialwoohoogamers task.wait() is simply more accurate and better version on wait()
do not use wait() use task.wait()
ceo of not knowing what hes talking about 🔥🔥🔥🔥
💀
Thats pretty sick, you should cover the other task. functions!
It's funny how I started watching your tutorials occasionally for fun because of that one tutorial where you taught me how to love
I have been making an earthbending game but because I didn't know this, you had to wait for every ability to completely finish before using another one. This has been a lifesaver.
Me watching your videos as if I don't already know this information but your videos are always fun, engaging, and informative that I still watch through the whole thing ❤
You're doing the world such a great service. Keep it up.
i just got into scripting and this is so helpful. thanks!
i used to watch you since one of your first video , keep it up , your videos are very interesting
Task.delay is actually the only way to get a delay in JavaScript without a separate library (obviously it’s not called task.delay though)
I learned about this recently and it is a new version of coroutines and is extremely useful
The part where he has to check if the function, that spawns, has to use () is the equivalent of using a calculator to double check 10 + 10. Like you know but you never know if you don't know.
you have to assign a variable to task.cancel to cancel that thread:
local newThread = task.spawn(functionName)
task.cancel(newThread)
Dude you're too good man, love your explanations. Will you ever make like a scripting series or are you more focused on tips and tricks?
i think task.cancel is used like that :
local thread1 = task.spawn(function)
task.cancel(thread1)
its very useful for things like if idk you want to have multiple things going on for multiple players so like idk a sword system and you can do damage to objects but you want a cooldown if you add a cooldown on the server it will be for everyone instead of you can use this and have it only have a cooldown for the 1 player on the server
It greatly reduces the writing of code, Thanks!
Easy summary: play in background
oh my god. i've been scripting for a while and i was unaware that you could cancel spawned tasks. i knew you could cancel delayed tasks before they begin, but i though that was all cancel was used for
GOOD VIDEO KEEP IT UP and you'll be a very successful , I CAN SEE IT.
lol already knew this exist really useful though I use it almost everytime I code something
I really wanted to take your course, but unfortunately I don't know English, I can only read words in English and understand at best, but I can't understand spoken words
I've been repeatedly using coroutines until this very video.
I got coroutine wrap and task spawn confused apparently :/ also thanks for help
Oh my god if I would've found this sooner
is this the same as coroutines?
I think there are 2 options for task.cancel()
Inside of a task, you should be able to run task.cancel() by itself or task.cancel(self)
Outside of a task you probably need to write the task to an object, so local task1 = task.spawn()
bro tried to teach us but ended up learning himself
so this is basically like coroutines but much easier to understand
it's like a less laggy coroutine.wrap
So, it's literally just asynchronous code in a single script instance. Nice IG, but this is why Luau is somewhat underwhelming when compared to other languages. I've always made the argument that if Roblox utilized its engine's chief language, C++, for its OOP task, it would be much more efficient and effective. But, then again, with Luau being designed for novice programmers, I guess it finds a good balance between implementing new libraries and introducing new people to coding. Nonetheless, this is a seriously effective method! Thanks.
This is actually so useful, thanks for the video. I was literally having a problem a few days ago where a thing wasn't running fast enough and the game was breaking, but I could see how task.spawn can be really useful in some situations. Will definitely be saving this for later!
Roblox devs discover multithreadding
sounds like coroutines but this is good thanks
Bro I have got 1 question how do you disconnect a spawned function ?
this guy is just existing and give us life lessons
i have read task.spawn had throttling, so i used corutines
spawn() has throttling, task.spawn() does not.
You should make a video about DataStores
What i used to do was make a function that coroutines a function... It kinda speed up everything. Imo coroutines are way better
Thanks
i was strugglin with this yesterday lol
where is my next love tutorial byteblox
Soon
another banger tutorial bbg
me an my cousin trying to be roblox developer do you have/know any video series that can help me and my cousin ?
Didn't know roblox was capable of multi threading!
Actors are the only way to properly run things on multiple cpu cores, task.spawn and coroutines run things on virtualized threads which go on a single core's task scheduler (meaning it may be faster but its certainly not going to be 'multithreading')
Can you make a tutorial on how to make a moving train like in jailbreak?
i feel so dumb lol
Bro I replaced all my script with something else, so what do I do! Ctrl Z doesn’t work!!!!😭🙏
Script recovery probably, look it up
I’m watching this as if I actually write code
What is the difference between task.wait(0.5) and wait(0.5)?
Wait is slower than task.wait
oh so basically it ignores the task.wait()?
No
Its treating the task.wait() as if it wasnt part of the loop, so the loop will call the function a bunch of times super quickly but the function itself will wait 2 seconds before printing the message.
Its kinda complicated and hard to explain, but its helpful when you want to add delay in functions without adding delay in loops.
If you did this without the task.spawn() you would need 5 scripts for the same effect. Meaning, it'll print "message" 5 times every two seconds.
no it does multiple things at the same time
To save a thread do
Variable = task.delay(stuff here)
Task.cancel(Variable)
if im not wrong, in this case, does it start all 5 functions as soon as it can rather than doing each wait 1 by 1 and it having to wait each time
Exactly. It creates a new “thread” for each function rather than running all 5 on one thread, one by one
awesome sauce@@byteblox100
awesome sauce@@byteblox100
You can also use coroutines for this
the idea of task.spawn/task.defer is that they're simplier and an alternative to corountines
What is the difference between this and a Coroutine?
similar thing but coroutines have more features
bro is stalling himself 💀
Hey, is it different from coroutines?
Nah it’s basically the same thing
local wait = task.wait
:troll:
bruh u dont use task.wait but u use task.spawn choose will u use task or not
Oh so this is Roblox threading?
yes
i like your videos
how would you use task.defer in a practical sense since i see that its not as used as the others
Task.defer seems to hold something off until the VERY END of the frame. So if we start task.defer during frame 10, it will defer its function until everything else is done for that frame
task.spawn() will spawn the task immediatly which is not good for the lua engine schedular. task.defer is always recommended as it runs the thread at the next resumption cycle which is optimal for the luau engine. Only use task.spawn when it is absolutly necessary for the thing to run at that exact moment.
task.spawn() runs functions asyncronously.
alr
Bro stop spamming the word “right”
for running, you could do a "Run" instead of a "Play" if you only want to run the server only, not the client
Man should've watched sleitnick's video before making this one 💀
wont this cause memory leaks
no
Why am I watching this? I don't know how to script
hey bro, you can make a tutorial of How to animate objects? Exemple: Doors, closets...
Check out my tutorial on tweening
but with "AnimationControler" not tween@@byteblox100
If you don't want to tween, Create a rig with animationController. Note that your model needs a BasePart and all parts welded to it
or just spawn, please at least explain to them what task does first bro ngl
spawn is deprecated due to it being extremely old technology
task is a library that recreates these older functions but improves them drastically with modern fixes
they cant simply replace the old functions due to compatibility issues, but if you dont want to include the task, just do the following example at the beginning of your scripts
local spawn = task.spawn
why not call this video `tutorial on multithreading`?
Less views lol
@@byteblox100 what if i told you, less is more?
nice video
literally ntts roblox tutorials
no u
Hey, I have a question, what's the difference between "spawn()" and "task.spawn()"?
task is faster
spawn is a older system that was outclassed later by coroutines, which has now been modernized into task.spawn and task.defer
r u sure this will sav me time
coroutine is better bro
bro took 4 minutes to get to the point
hamburger
you could also do:
0 = time
delay(0 ,function()
print("idk")
end)
0 = time!?!?!?
yep, 0 = how much time you want it to wait, in this case is 0@@QUBIQUBED
bro what is this BAHAHA
no bro, task.delay(delaytime, function()
- -your multithreaded function here
end)
using delay, spawn, wait, without the task. causes throtelling idk how to write this
E
lmao everthing in this video is wrong and I just hope you know that
Like half my videos are wrong lmao
save me hours
save me hours
save me hours
FIRST W
SECOND
So, maybe I'm lil dumb for my level, but what is the difference between coroutine.wrap and task.spawn() ? Please reply the ones who *understands* it.
You can start and stop a coroutine, but not a task.spawn, which will keep running until the script finishes
WHY ARE YOU NOT USING TASK.WAIT INSTEAD OF WAIT!?
BECAUSE IM STRAIGHT 🔥🔥🔥
@@byteblox100 who wouldn't be
bite blozx
why tf do you make these tutorials when you don't know the full topic
anyways task.spawn returns a thread
task.spawn: (function: () -> nil, ...: variant) -> thread
task.cancel: (thread: thread) -> nil
coroutines also return threads as well as task.delay and task.defer
and for those who want a tl;dr on the task library here you go:
* task.spawn: (function: () -> nil, ...: variant) -> thread
calls/resumes the given function immediately
* task.defer: (function: () -> nil, ...: variant) -> thread
calls/resumes the given function on the end of the current invocation cycle (think of it like the function being put off until the end of the frame/heartbeat)
* task.cancel: (thread: thread) -> nil
cancels the given thread
* task.wait: (seconds: number): number
yields the given script for [seconds] seconds. note that it will return the real amount of time it yielded for
* task.desynchronize: () -> nil
this is for parallel luau which is its on can of worms
* task.synchronize: () -> nil
see task.desynchronize
also stop trying to harvest emails please, its really sad
im not reading allat 😭😭🙏
Some people like pre scripted tutorials and others like a raw tutorial nothing wrong with that
Its harder to explain something when you can't do something over and over
Side note: sorry but how you wrote it didn't explain much
@@chromatyp3 why would he harvest emails lol
I used coroutines