This is a bit of an ambitious project. I was thinking it’d be a cool feature in my open world game if I could get some trucks to drive down the road and the player has to assault the caravan. Almost like the train in jailbreak, but with trucks.
So I figured a good way to make a truck go down a path is the tween service! Now, unfortunately, I wouldn’t know how to pull it off. Basically, I’d like a simple breakdown of how tween works. I’m not the best coder…
I think once I have the trucks moving I’ll work on the attack part, but for now I’m taking it step by step.
Basically, the helicopter follows an anchored part that’s being tweened to the desired position. It follows this part with alignposition and alignorientation, although the alignorientation follows a proxy part so that I can have more control over the rotation.
I see what you mean by welding it to a part, but I’m lost to all the other Mumbo Jumbo (Mumbo’s a great youtuber!"). That helicopter is quite cool though.
It’s not welded. The part is being tweened on the server so that the server has complete control over the helictoper, but the helicopter is not on the server at all. When the helicopter is to be moved, the client creates the helicopter and attaches AlignPosition to the tween part.
This is because the helicopter being moved on the server would be choppy and create unnecessary lag, it’s far better to let the copter only be on the client. One note is that if the tween part is moved too fast, the helicopter will start flipping out so you might just want to do everything on the client.
You don’t have to attach the AlignOrientation to a proxy part, I only do that for complete control over orientation for ambient movements since helicopters dont stay anchored in one orientation. With a truck I don’t think it will be a problem.
No it isn’t for gui. an example for tweenService is
local tweenService = game:GetService("TweenService")
local brick = script.Parent
local tweeningInfo = TweenInfo.new(10,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,1,true,0.5) -- the details of the tween
local properties = {Position = Vector3.new(--[[write desired pos here]])} -- this is where you want stuff to happen such as changing position or size or any other property of the brick.
local tween = tweenService:Create(brick,tweeningInfo,properties) -- the tween is being created hence the create
tween:Play()
And, you cannot tween a thing with multiple parts as that would require you tweening ALL the parts or using the primary parts.
EDIT: spelling error was corrected
I have a very shallow understanding of coding, and I kind of just learned to do loops, change part properties and such. But if the truck is only moving from a single person’s screen, how would the other players interact with it? Also, what’s AlignOrientation and proxy parts?
Client sided means that itll show for the player only, so everyone will see it.
ex: if the truck in player 1 screen was moving but suddenly stopped for any unknown reason, player 2 wouldn’t see it stop as the stopped truck is CLIENT sided. player2 would only see their truck still moving.
Yes, but if it was just on the server wouldn’t the truck just behave the same for everyone? What I mean is my game has PVP so I was hoping that they could just fight on the truck while getting their loot.
I understand. This kind of thing is probably hard to understand for people new to scripting, so for now you can just tween the trucks on the server and not worry about client-siding. It does help a lot with lag and how smooth the trucks are though. If you want to learn, I suggest starting with network ownership although it isn’t related to what I’m doing with my helicopter.
Yeah, does that involve local scripts or normal ones? I’m not quite sure the difference, but I have a feeling it involves that. Edit: the client side things
That would make sense, I was messing around with a music script with a local version and when my character died the song restarted, but for my friend it didn’t. It’s all very new stuff to me, sorry for being a little below par when it comes to this kind of stuff.
Not sure if anyone has mentioned this, but if your trick is a Model, just set the Model.PrimaryPart to a part then use something like this:
local TweenService = game:GetService("TweenService")
local checkpoints = {} -- invisible parts along the road in the workspace
local truckModel = -- path to truck model here & make sure you set the primary part property of the model
local truckPrimaryPart = truckModel.PrimaryPart
-- this creates a linear animation TweenInfo configuration taking animationTime long
function createNewTweenConfig(animationTime)
return TweenInfo.new(
animationTime,
Enum.EasingStyle.Linear, -- you could change this or add more params above
Enum.EasingDirection.Out,
0,
false,
0
)
end
-- this drives the truck to the specified checkpointPart and it takes timeItTakes to arrive
function driveTruckToCheckpoint(checkpointPart, timeItTakes)
TweenService:Create(
truckPrimaryPart,
createNewTweenConfig(timeItTakes), -- creates a new tween info
{
CFrame = checkpointPart.CFrame
}
):Play()
wait(timeItTakes)
end
for i, checkpoint in pairs(checkpoints) do
driveTruckToCheckpoint(checkpoints[i], 30) -- this drives the truck to every checkpoints taking 30 seconds to get to each one
end
Alright, being the dumb dumb I am when it comes to coding, I’m going to try to digest it and explain what I understand… The code starts the tween service, you got some variables for the truck, and it’s root and the checkpoints (that’s helpful). Not sure what the TweenInfo.new() is… and the truck tries to go to different points and there’s a set number of seconds it takes to get to each one?
I’m also confused how I could add multiple checkpoints in the little {}