Making a cargo caravan. Or at least a truck with tween

The PrimaryPart of a Model is the Part whose CFrame (if it moves) moved the whole model along with it.

Also, TweenInfo is just data you give to TweenService to describe the animation. You can read more about it here: TweenInfo | Documentation - Roblox Creator Hub

Next, checkpoints is a table which uses curly braces like this: {}
In your game, you could add invisible parts to the workspace called something like Checkpoint1, Checkpoint2, and Checkpoint3 and put them along a road or wherever you want your truck to drive. To add them to the checkpoints table, you could write your checkpoints table like so:

local checkpoints = {workspace.Checkpoint1, workspace.Checkpoint2, workspace.Checkpoint3}

createNewTweenConfig(animationTime) is a function which takes a number as a parameter called its animationTime. It spits out or returns a TweenInfo, which is just the animation details and the TweenInfo specifies how long that animation will take to complete by assigning the first parameter of TweenInfo.new() to be animationTime.

driveTruckToCheckpoint(checkpointPart, timeItTakes) takes two parameters. It takes a checkpointPart, which is just one of the parts in your checkpoints table or any part that you want. It also takes a timeItTakes which basically is how long you want the drive to take. Inside this function, we actually create the animation using TweenService:Create()
The Create function of TweenService takes your truck model, the TweenInfo returned from createNewTweenConfig(timeItTakes), and another table of properties which you want the animation to change. The :Create() function just created the animation, so I call :Play() at the end of it to actually play the animation created. TweenService:Create(...):Play() basically creates the animation of a certain length, and moves your truck to the desired checkPointPart by “tweening” the CFrame of your truck model’s PrimaryPart to the checkpoint part’s CFrame. At the end, I just wait(timeItTakes) to ensure that you wait until the animation is done before moving the truck again.

The for loop at the end of the code just goes through every checkpoint in your checkpoints table and animates your truck to each one sequentially. This means it would visit the first thing in the table, the second thing in the table, and so on. You can probably remove this, as it was just an example of calling the functions I provided.

I hope this helps you comprehend! Good luck! :slight_smile:

1 Like

Thank you! That is verrrry helpful. This will add a lot of depth in my game.

robloxapp-20200428-1155057.wmv (317.9 KB)

I think the hotdog forgot it shell. is it because it should be unanchored? also do I just turn the check points to make it turn?

You should make the checkpoints anchored, floating parts. For the truck, it does not have to be anchored. You can unanchor the PrimaryPart and weld it to the other parts in the truck so that even though it’s unanchored, it stays in its position and only moves when you change the CFrame of the PrimaryPart.

Thank you. I’ll tell you this: you made my life much easier, once again thanks!

robloxapp-20200428-2141207.wmv (1.4 MB)

I made a model for the script. I think it’s nice. Appreciate everyone’s help.

Hey, I think I got it to work. https://youtu.be/L3Ejj-PN-Tw thanks

I think now after learning this I will take a look at the tutorial how to load and unload models.
But I think the hard part is done

1 Like