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!