How to move Vehicle in one Direction

So i have these:

local function ConvertToKMH(StudsPerSecond)
local kilometer = (StudsPerSecond/3.57)*1000
local seconds = 3600
return kilometer/seconds
end

local train = – part from which you will calculate the velocity
assemblylinearvelocity += ConvertToKMH(train.Velocity.Magnitude)

But how could i now change the Speed of the Vehicle +1 Kmh? I just need one Direction because its a Train.

I don’t quite understand what your asking for but maybe this might help

local runService = game:GetService("RunService")
local train = ...

local function ConvertToKMH(studsPerSecond)
	local metersPerSecond = studsPerSecond / 3.57
	local kilometersPerHour = metersPerSecond * 3.6
	return kilometersPerHour
end

local function ConvertToSPS(kilometersPerHour)
	local metersPerSecond = kilometersPerHour / 3.6
	local studsPerSecond = metersPerSecond * 3.57
	return studsPerSecond
end

runService.Heartbeat:Connect(function(deltaTime)
	-- move the train forward 1 KMH
	train.position += train.CFrame.LookVector * ConvertToSPS(1) * deltaTime
end)

this video might also help

1 Like

Could u help me how its get faster everytime like from 1 to 80 kmh when u click a Button and do i need connection? Because when player use autoclicker and decrease and accelerate fast the train can bugg and be in 80 kmh in 10 sec.

Hey, i have a Question, what do i need to use ConvertToSPS(1) or ConvertToKMH(1), because i want to convert it to KMH but KMH is not printing

local runService = game:GetService("RunService")

local function ConvertToKMH(studsPerSecond)
	local metersPerSecond = studsPerSecond / 3.57
	local kilometersPerHour = metersPerSecond * 3.6
	return kilometersPerHour
end

local function ConvertToSPS(kilometersPerHour)
	local metersPerSecond = kilometersPerHour / 3.6
	local studsPerSecond = metersPerSecond * 3.57
	return studsPerSecond
end

local train = ...
local speed = 0
local minSpeed = 0
local maxSpeed = ConvertToSPS(80)

runService.Heartbeat:Connect(function(deltaTime)
	-- move the train forward by the speed every heartbeat
	train.position += train.CFrame.LookVector * speed * deltaTime
end)

local function SpeedUpButton()
	-- increase the speed by 1 KMH
	speed = math.min(speed + ConvertToSPS(1), maxSpeed)
end

local function SpeedDownButton()
	-- reduce the speed by 1 KMH
	speed = math.max(speed - ConvertToSPS(1), minSpeed)
end

robloxapp-20220806-0503067.wmv (3,7 MB)

Why is this happening, without Delta Time its working but with Delta Time the other Parts of the Train are going slowly