Move a multi-part vehicle forward with the keyboard by updating the model's CFrame, and steer by rotating it.
A car, a boat, or a moving platform is really just a group of . In this lesson you'll move them all together by treating the vehicle's root — the model — as the thing that moves, and steering with A and D while driving with W and S.
Every vehicle is a Model whose position you control entirely through its root . Moving that root moves every welded child with it:
local car = workspace:WaitForChild("Car")
local root = car.PrimaryPart -- the part the model pivots around
-- Move the whole car forward 1 stud
car:PivotTo(root.CFrame + root.CFrame.LookVector)
PivotTo moves the entire model by its root's . Because the body, wheels, and seats are welded under that root, they all travel together — you never move a wheel by itself.
Make sure the vehicle's body actually is the PrimaryPart (car.PrimaryPart = car.Body), and that the child are welded to it. Otherwise PivotTo can't move them as one unit.
The method that moves an entire model by its root part's CFrame is
Drive with W/S for forward and reverse, A/D to steer. Use UserInputService so input works all the time, not only when a GUI is focused:
local UserInputService = game:GetService("UserInputService")
local keys = {}
UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.Keyboard then
keys[input.KeyCode] = true
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
keys[input.KeyCode] = false
end
end)
local function isDown(key)
return keys[key] == true
end
Tracking keys as a means you can check multiple keys per frame — pressing W and D at once drives forward while turning, which is how real driving feels.
Why record keys in a table instead of firing an event on every keypress?
The simplest movement adds the car's LookVector to its position each frame:
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function(dt)
local speed = 40 -- studs per second
if isDown(Enum.KeyCode.W) then
local direction = root.CFrame.LookVector
car:PivotTo(root.CFrame + direction * speed * dt)
end
end)
Multiplying the direction by speed * dt makes the movement frame-rate independent: dt is the time since the last frame, so whether you run at 30 or 240 FPS, the car covers the same distance per second.
The skeleton moves forward using LookVector. Write the one line inside the loop that actually moves the car, using PivotTo, CFrame addition, and a speed of 40 times dt.
RunService.Heartbeat:Connect(function(dt)
local speed = 40
if isDown(Enum.KeyCode.W) then
-- move the car forward here
end
end)Steering is rotating the car around its own vertical axis before moving it. Use CFrame.fromEulerAnglesYXZ — the Y axis is up/down, so rotating around Y turns left and right:
local function steeringAngle(dt, keys)
local turn = 0
if isDown(Enum.KeyCode.A) then turn = turn + 1 end
if isDown(Enum.KeyCode.D) then turn = turn - 1 end
return turn * 2 * dt -- about 2 rad/s
end
RunService.Heartbeat:Connect(function(dt)
local speed = 40
local turn = steeringAngle(dt)
-- build the new CFrame: rotated, then moved
local rotated = root.CFrame * CFrame.Angles(0, turn, 0)
root.CFrame = rotated
car:PivotTo(root.CFrame + root.CFrame.LookVector * speed * dt)
end)
Multiplying two composes them: root.CFrame * CFrame.Angles(0, turn, 0) rotates the car around its own origin before the forward movement is applied. A positive angle turns one way, negative the other.
Combine rotation and forward movement into a single PivotTo so the wheels don't slide sideways from a separate translation. The composed rotates around the car's own origin and then shifts it forward:
car:PivotTo(root.CFrame * CFrame.Angles(0, turn, 0) * CFrame.new(0, 0, -speed * dt))
Rotating around Y then moving along the (now-rotated) forward axis is exactly how a car turns a corner without drifting.
Forward, reverse, and steering all funnel into one place: building a new and calling PivotTo once per frame.
-- W/S: forward/back along LookVector
-- A/D: rotate around the Y axis
-- One PivotTo with a composed CFrame per frame
The whole vehicle is just a welded model whose PrimaryPart you rewrite every frame. Physics steps in only when the wheels touch the ground — the Roblox physics engine handles resting and collision for you, so you only write the driver.
PivotTo the model.dt. Movement without delta time is twice as fast at 60 FPS as at 30. Always multiply by dt.PivotTo silently does nothing useful without a PrimaryPart, so set car.PrimaryPart explicitly.Next: teleporting — warp a between zones and places.