Tween Service - Roblox Advanced Scripting #12 — Transcript
Full transcript
- 0:00whoa wait a minute I've seen this before what is it doing all the way out here oh whoa whoa bro
- 0:10hold up I need to analyze this really quick what is going on with this part let's see okay we have
- 0:16a script uh oh it uses tween service okay that actually makes more sense this syntax just looks
- 0:25so ugly though I could definitely do a better job with that I mean no wonder this speeding
- 0:29wall doesn't look to be a very good programmer I mean he says right here his family has left
- 0:33him because he has chronic anger so we probably wouldn't want to mess with him I will now that I
- 0:38understand that this uses tween service I think that'll be the most appropriate thing to talk
- 0:42about in this episode and if you're still sort of confused tween service with the ugly line of code
- 0:47that you saw basically made this speeding wall move super fast in this direction in order to
- 0:53kill me and it was able to do it so smoothly as well like you saw how smooth this wall was
- 0:58moving across this direction when we gave it an end goal and also a time to be able to get
- 1:04to where it needed to be and so I think that's something we should be able to understand is is
- 1:09be able to move these parts very smoothly and not even just that tween service can do a whole bunch
- 1:13of things for you which we're going to go a bit more into in a little bit but let's not Implement
- 1:19these just yet because I want you to fully get a grasp of the use of tween service and how we can
- 1:24use them so with that being said let me show you a little something before we begin all right let's
- 1:28think about this for a minute we're going to be re-enabling our script for this speeding wall just
- 1:34to see what's really happening behind the scenes when we use tween surface to move this part from
- 1:40where it originally was to its its uh end goal so let's hit play and watch as the script changes its
- 1:48properties through tween service so let's open up the works Explorer with parts and let's go
- 1:52to the position so the position should be moving very incrementally from its original position so
- 2:00I'm actually going to show you that one more time just so that you can really see what's happening
- 2:04so I'm making the part specifically move in its X or in its X position with the position property
- 2:12and it's slowly moving from where it originally was to its end goal which we specified to be -200
- 2:19studs from its original position so it wasn't just going from where it originally was and
- 2:24just simply changed the position to whatever it was over there it progressively changed the
- 2:29X property to go from where it was to its end position over there and so that's essentially
- 2:34what tween service is tween service allows you to interpolate or or pretty much tween go from
- 2:41its starting position to its ending position very smoothly and incrementally not very suddenly where
- 2:48we just change the position of let's say it's Z to 200 we just it basically teleported back to where
- 2:55it originally was um without having that smooth positional changes and that's basically that you
- 3:02can do this with most numerical properties like not just position but you can even do orientation
- 3:08and you can even do values that go from 0o to one like transparency reflectance you can even
- 3:13change the color too and all that sort of stuff there's a whole bunch of properties you can work
- 3:17with that's compatible with tween service and so we're going to be diving deep into a couple
- 3:22examples of how we can use tween service inside of our Roblox games so that being said let's get
- 3:26straight to implementing now that we understand it let's create tween to quote unquote move these
- 3:33instances or objects around inside of our game and the first thing we're going to do is just create a
- 3:39simple part where we can move the position of that part and so we can see it move in real time to a
- 3:46desired end goal that we do have so we're going to do that by first going to model and then hitting
- 3:51part uh let's scale this up just a little bit so that we can make it look nice let's make it
- 3:57uh blue and let's also make it an ined as well so now that we have our part let's rename this
- 4:03to moving part all right and so now that we have our part let's create a script inside of
- 4:08this part we're going to hit the plus sign next to moving part let's create a script and let's
- 4:13delete this code that's over here and so here's what we're going to do we need to make reference
- 4:17to Tween service because that's obviously the service we're going to use to create these twns
- 4:23we're going to say local tween service equals game colon get service tween service and then
- 4:34we're also going to make reference to our moving Parts by saying local part equals script. parent
- 4:40all right so now that we have our script that references tween service and also our part here
- 4:45what we want to do is create a tween that has the part start at its position and then we're going
- 4:51to specify what specific position we want this tween to animate this part to move to where we
- 4:59want it to uh with our end goal before we create the tween there's two more important pieces of
- 5:05information that we need before we can get to creating it one of them is tween info and the
- 5:11other one is our goal so let's so let me explain what tween info is it's basically a data type that
- 5:19provides multiple values that lets us customize our tween the way we want to animate a part to do
- 5:26something specific like we can specif spe ify how fast or how slow this tween is going to animate
- 5:34we can specify the the style of how it animates from one place to the next if we wanted to repeat
- 5:42it more than once and if we want there to be like a delay of some sort when it goes from its
- 5:46starting position to its end position there's many possibilities for this tween info uh data type but
- 5:52I'm going to be showing you a basic example of creating a tween info data type so we're going
- 5:58to say local tween info equals tween info. new so we're going to use the new Constructor with
- 6:08the open close parenthesis and as you can see there's a whole bunch of arguments we can put
- 6:13inside of our tween info object um I would say at the very least you should have this argument
- 6:19here called time and it takes in a number so this is pretty much how fast or how slow you want this
- 6:26tween to uh execute when you run it um so I would say if you have at least that then I'd say you're
- 6:32good to go all the other stuff like easing style easing Direction and everything like that I would
- 6:36say it's pretty important but not as important as the time we will go over some of the other
- 6:42properties in a little bit but for right now let's just set a time which takes in a number we're
- 6:47going to set this to five because this represents 5 Seconds uh and we could just leave it like this
- 6:54so that's the second piece of information but now the final piece of information we need is the the
- 6:59goal also known as the end result how do we want this tween to end so remember when I said that we
- 7:06have a starting point for our instance and then we have an end goal for our tween once we're finished
- 7:13with it in this case our end goal for this part would be moving it to a specific position in our
- 7:193D World so let's just say we want to move this in this direction by about 51 studs the position
- 7:26here will be about 51 studs on the Z AIS with a position of 452 and 51 so let's specify this
- 7:34position 452 and 51 as our positional goal and so how do we write that as our goal so the way
- 7:42it's going to work is our goal is pretty much a table full of properties that we want this tween
- 7:48to achieve so it could be more than just positions it could even be sizes and other numerical values
- 7:55that you can put that's compatible with tween service so here's what it's going to look like
- 7:59like we're going to say local goal equals open and close hard brackets because this is going
- 8:05to be a table full of information and let's drop a line if you know table syntax then you pretty
- 8:11much know the different ways you can create a table but I'm going to do it like this so our
- 8:16goal is just to Simply change the position to our specific coordinates which was 45 2 and 51
- 8:24so let's say position equals vector 3. new because as you know position is a vector 3 data type we're
- 8:33going to say 45 2 and 51 and then that is pretty much our goal right here remember that position is
- 8:40K sensitive so you should have the p is capital uh but this is basically our only goal that we
- 8:45need for this part it's just to move from where it originally was to this specific place right here
- 8:52and that's going to be at 452 and 51 all right so now we have all bits of information to make
- 8:58this happen now let's create the tween we're going to drop two lines and we're going to say
- 9:04local tween equals tween service colon create open and close parentheses and so this takes
- 9:14in three arguments with all of the things that we created previously so the first one is going to be
- 9:20the instance itself which is just going to be our blue part right here so we're just going to put in
- 9:25part comma and then our tween info object which we already created up here so it's going to be tween
- 9:33info and then our last bit of information is the property table also known as our goal what we want
- 9:40to achieve with this tween so let's pass in our goal argument there as well Okay cool so now we
- 9:46have our tween but if we play the game nothing's going to happen because we haven't activated our
- 9:52tween all we did was just create it so the way we activate this tween is by dropping a line where
- 9:59we're going to say tween and we're going to use the function play open and close parentheses so
- 10:06this is basically how we create a tween on Roblox let's also add in a quick task. weight statement
- 10:12before this plays so that we can fully see uh the part move when we load in so let's say task. wait
- 10:20uh 2 seconds all right so let's go into the game and hit run so that we can see this part move
- 10:26while it's animating all right and as you can see this part is slowly moving from where it began to
- 10:33the end position just like that we didn't have to abruptly move the part from where it was to
- 10:41instantly being where we want the end goal to be it made a cool little animation that started from
- 10:47where it was to the end position and there's a lot of things we can change with this move
- 10:52property so we can modify it with our tween info with things like easing style and easing
- 10:58Direction now with these properties it's going to require a lot of just experimentation to know
- 11:04the difference between all of them and which one works best for you easing style is essentially
- 11:08how we want this part to animate when it's going from its starting position to its end position
- 11:15so an example of an easing style would be if we had the part go from its beginning to its end in
- 11:23a very linear fashion without anything fancy and then it'll just abruptly stop or you can
- 11:30have it start slow and then it accelerates really fast until it reaches the end so it's something
- 11:35along the lines of that I'm going to show you an example from someone on Twitter that made a great
- 11:41comparison side by side of these easing style types all right this is an old gift from 2015
- 11:47so it is kind of outdated but it still explains how easing Styles work and this post is by Aussie
- 11:53Pig and I think he's done a great representation of showing the difference between these easing
- 11:57Style enums so let me just play it for you just to show you all these different types of easing
- 12:03style options so this is what it essentially looks like when you go from its starting position to the
- 12:11end position and you can have it go the other way around as well if you go from its ending position
- 12:17to its starting position so this is what it looks like in reverse and I'm going to play that for you
- 12:21again this is what it looks like from start to end and this is what it looks like from end to start
- 12:27and so we can essentially do this not only with UI but we can also do this with parts like with
- 12:33our moving part in studio so I I hope this um gave you a bit more understanding of easing Styles all
- 12:39right so now let's add an easing style to our tween that we previously created in our tween
- 12:44info so I Believe by default the easing style is something called sign uh I'm going to show
- 12:51you what that looks like so let's separate this with a comma and now we're into our easing style
- 12:56and remember easing style is an Eno so we have to so it's kind of like a library of different
- 13:02values that we have to uh fetch we basically have to say enum do eing style Dot and now we have all
- 13:12of these different easing style types that we can pick from like I mentioned I believe sign is the
- 13:18default uh easing style so that's why we were able to see this animate without us specifying
- 13:24an easing style because Roblox by default picked sign uh but let's change this to something like
- 13:31bounce instead to really see the difference with these tween so this is pretty much it uh let's go
- 13:38into the game and hit run to see the difference with our new easing style all right so as you
- 13:44can tell there was a pretty big difference there compared to the one we had before with sign with
- 13:49bounce it was definitely a lot more bouncy I guess and there's even more properties we can change as
- 13:55well we can change uh the easing Direction by saying enum doing direction do in in out and
- 14:03then out I believe the default is in but you can change it to out meaning like it's going
- 14:08in reverse uh you could experiment with these if you want to it's not too terribly important but
- 14:13that's another thing you can add there's other properties like repeat count which is just a
- 14:17number or reverse which is a Boolean or our delay time which is also a number so not all of this
- 14:25really matters too much and you don't need every single property in tween info I would say the most
- 14:31important one you need is the time the duration of the tween when you play it but other than that
- 14:37all of these other things you can add them if you want to be more specific with your tween but that
- 14:42is essentially the tween info data type that you can use to customize your tweens when you use them
- 14:47in your games let's add more goals let's say we also want to change the size of this part as it's
- 14:53moving along to its end position so the current size is 4X 4x4 but what if we change it to 10 x
- 15:0010 x 10 while it's moving a long way to reach its end so we're just simply going to create
- 15:06a new entry in our goal by by making a comma and then hitting enter let's also change the size to
- 15:14another Vector 3 value uh by saying 10 by 10 by 10 all right so now let's see our part if we decide
- 15:22to add another goal to it alongside the moving one so as you can see it's scaling up while it's also
- 15:27moving so we can do a whole bunch of things with our end result goal uh inside of the same tween
- 15:33so that's another useful piece of information to know about there are also tween functions that I
- 15:37want to introduce to you the first one I already did which was tween play which obviously plays the
- 15:43tween that we created but there's two other ones that I want to show you the second one being that
- 15:49we can actually pause the tween Midway without it completing uh we can do this at any point during
- 15:55our script because if we play a tween that doesn't mean it's going to pause the script with whatever
- 16:02other code that's going to be down here so that's why we can just pause this tween if we want to
- 16:07so let's say about after 1 second we simply just pause this tween uh just abruptly we're going to
- 16:15put in a task. weight function right here with 1 second and then down here we're going to say
- 16:20tween colon pause open and close parentheses so if we go into the game now after about 1 second
- 16:27the playing tween should then abruptly stop so it just stopped right here but it hasn't reset
- 16:35nor has it completed because it's currently uh stuck in pause mode right now so what we can do in
- 16:42order to continue the tween uh we can just simply say well first let's put a task. wa for another
- 16:49second again we can just simply say tween colon play again so we're using the same play Method
- 16:56there's no such thing as like a a Zoom method or continue method or anything like that we just
- 17:01simply say twe colon play again to resume where it left off so if we play this now it's going to take
- 17:10a second to pause and then it's going to continue where it left off to then finish what it started
- 17:17and finally there's one more function which is just canceling it entirely so after we pause it
- 17:22uh we're going to wait a second and instead of playing it again let's just cancel it completely
- 17:27and now let's see what happens happens when we play the game so it's going to move and then it's
- 17:31going to stop after about 1 second it's just going to cancel the tween it's kind of hard to tell but
- 17:36this tween no longer exists because we decided to cancel the tween so now the tween cannot continue
- 17:42where it left off because we completely canceled the tween and now there's no more tween for this
- 17:48part now there's one event that's special with tween service and that is the event of detecting
- 17:54when our tween finishes with whatever object or inst since it was trying to Tween uh we can do
- 18:00this inside of our script after we play the tween for the first time so let's delete our code down
- 18:06here with pausing and cancelling and let's write in an event that detects when our tween finishes
- 18:12so let's drop two lines and we're going to say tween do completed colon connect function open
- 18:21and close parentheses enter and then we can just pretty much say whatever we want here with our
- 18:26print statement we can just say tween has been completed that's pretty much it we can just go
- 18:33into the game and see our change in the output once this tween has finished what it needed to
- 18:39uh finish so the tween finishes and then in the output it says tween has been completed so the
- 18:46event has been fired Su successfully uh after the tween was finished now this is one way you can use
- 18:53this event you can basically fire something after this tween has been completed but there's also
- 18:58another way of doing this that pretty much acts as a task. weight function but we have a very precise
- 19:04way of knowing when this tween finishes what we can do instead is delete all of this here up until
- 19:10the function declaration so let's delete that so we're simply going to say tween do completed colon
- 19:17weight open and close parentheses this is the entire code right here and then down here what
- 19:22we can do is make the print statement saying this TW uh tween has been finished essentially what
- 19:30we're doing here is we're creating a very accurate weight statement uh to wait until this tween has
- 19:35been completed and then we fire whatever code is um here with the rest of the script so let's go
- 19:42into the game and hit run and we should see the same exact result with our script this was just
- 19:48one other way of writing it so let's finish our tween and then down here it prints again
- 19:53this tween has been finished because we told the script to wait until the tween's been finished to
- 19:58to do whatever else was down here which was uh printing this print statement so those are two
- 20:03ways you can use the completed uh tween event but I usually use completed with a weight statement
- 20:11rather than connecting it to a new function to do whatever I wanted to do inside of a function
- 20:16so I hope you'll find great use with using this completed event and I believe that's the only
- 20:21event that's unique to Tween I hope this video served you as a good introduction to Tween service
- 20:27if the if this is your first time using tween service um I further made more improvements to
- 20:32my part by adding in an easing style of Bounce and I basically wrapped this around in a while
- 20:38true do statement to give me a random goal every single time by picking a random color and a random
- 20:46orientation and then play that tween and then just simply wait till that tween is done to do
- 20:50it all over again so you can do some pretty cool stuff with tween service um and so if you plan
- 20:56to use this in the future this is definitely a much greater way of animating your parts
- 21:01or instances to do what you want them to do uh in real time it's definitely more efficient than just
- 21:06using a normal while loop to manually change the properties of its positions or sizes or whatever
- 21:12you want it to do tween service just serves as a great tool to do the really complicated stuff
- 21:18for you and so that's what I really like about it my name is baldev and if you found this video to
- 21:22be helpful then be sure to like the video and if you haven't joined my Discord server the link to
- 21:26that is in the description but apart from that I will see you in the next episode take care
About this transcript
This page contains the full transcript of Tween Service - Roblox Advanced Scripting #12 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,027 words across 211 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.