Move Train in KMH [Video]

The script under me dont work because delayTime will bugg the HingeConstraint:
robloxapp-20220806-0503067.wmv (3,7 MB)

local runService = game:GetService("RunService")

local train = script.Parent

local speed = 80

local function ConvertToKMH(studsPerSecond)

local metersPerSecond = studsPerSecond / 3.57

local kilometersPerHour = metersPerSecond * 3.6

return kilometersPerHour

end

runService.Heartbeat:Connect(function(deltaTime)

-- move the train forward "speed" KMH

train."CFrame or Position, both works" += train.CFrame.RightVector * ConvertToKMH(speed) * deltaTime

end)

So i made this but its not working:

runService.Heartbeat:Connect(function(deltaTime)

-- move the train forward "speed" KMH

train.CFrame.RightVector += (speed/3.57)*1000

end)

So the problem is, without delaytime the Train will run good but with it the other Parts who are connected with Hinge will run slower

Why use a separate function to convert it?

Just make kilometersPerHour = studsPerSecond * 1.0084 in the bottom line and get rid of the function.

1 Like

Because somoene send me the script and why 1.0084?

Look at the calculations in the function.
If you put in 1 stud/sec in you get 1.0084 km/h as an answer.

Dont i also need 3.57?


Why? You have 2 conversions which means if you divide by 3.57, then multiply by 3.6 you get 1.0084.
It’s basic math.

Okay, like this?: train.CFrame.RightVector += speed * 1.0084

attempt to perform arithmetic (add) on Vector3 and number

It doesn’t take 3 braincells to understand the error.

You need to convert the right side of the equation into a Vector3, because as stated here RightVector is not infact a single integer.

With 3 Braincells u couldnt understand anything, i dont know what i should add after RightVector +=

I was gonna tell you but after treating me like that I don’t feel like it anymore.

hint: its Vector3.new(0,speed*1.0084,0) or something along those lines

U said it first HAHA and thanks

robloxapp-20220808-2259586.wmv (1,1 MB)

Move the numbers around, for instance try Vector3.new(speed * 1.0084,0,0) or Vector3.new(0,0,speed * 1.0084)

Yeah i did Vector3.new(0,0,speed * 1.0084) but its not working but this works:

local runService = game:GetService("RunService")

local train = script.Parent

runService.Heartbeat:Connect(function()

train.AssemblyLinearVelocity = script.Parent.CFrame.RightVector*-15

end)

But i dont need this why the other one dont work

You mentioned Yeah i did Vector3.new(0,0,speed * 1.0084) but its not working

But as @TestyLike3 said, did you try putting the 1.0084 in the X position?

Yeah i did it, it worked, i copied the Train to a other Game and tried it there but i forgott that i dont have Collision Group there thats because it didnt worked but thanks

Please mark the post that solved your issue with the Solution button so other people won’t read it to try to solve it.
It also helps if someone searches for a post about the topic. Your post would come up in the search as Solved.

I marked it to you already hours before just saw its unmarked

1 Like