Limiting Top Speed of a Car (A-Chassis Tune 6.52S2)

What do you want to achieve?
It’s simple, I would like to find a way to limit the top speed of a car. I want it so that the car functions properly up until the limited top speed is reached. Then it would stay at that speed no matter how much throttle I put in. Other aspects of the car shouldn’t be affected. Besides, I would also like to have the working code as a plugin to the chassis, like this (circled area):
Screenshot (64)_LI

The chassis I’m currently using is A-Chassis Tune 6.52S2 by SecondLogic.

What is the issue?
I have never seen such function implemented on any car with this chassis, therefore I don’t really know how I’m supposed to do this.

What solutions have you tried so far?
I somehow found a post made by TwentyTwoPilots that gets me around 70% of what I want, here is my current code:

local car = script.Parent.Car.Value
local limitedSpeed = 160 -- limited speed in mph
local _Tune = require(car:FindFirstChild("A-Chassis Tune"))
local _GThrot = script.Parent:FindFirstChild("Drive")._GThrot

function limit()
    local HoldSpeed = car.DriveSeat.Velocity.Magnitude

	if car.DriveSeat.Velocity.Magnitude < HoldSpeed and car.DriveSeat.Velocity.Magnitude < limitedSpeed then
		_GThrot = math.min(((HoldSpeed - car.DriveSeat.Velocity.Magnitude) / 10) + (_Tune.IdleThrottle * 2), 0.75)
	elseif car.DriveSeat.Velocity.Magnitude > HoldSpeed + 1 or car.DriveSeat.Velocity.Magnitude > limitedSpeed then
		_GThrot = 0
	end
	game:GetService("RunService").RenderStepped:Wait()

    _GThrot = 0
end

while true do
	game:GetService("RunService").RenderStepped:Wait()
	limit()
end

The only problem is that the variable _GThrot is in the Drive local script of the chassis, and I’m pretty sure the original code is supposed to be inserted in said script, which is what I don’t want. I am currently stuck on trying to properly get the _GThrot variable.

Any help is much appreciated, as this could be an essential part of my game’s cars.
-Keanny

7 Likes

Just find where _GThrot is received by the server script and math.clamp it from [0, max_throttle]

1 Like

Could you please elaborate on that? I don’t know how it can be done.

2 Likes

This is a pressing issue for me that I’d also like to solve. Does anyone else have knowledge as to how this could be achieved?

1 Like

You could try fiddling with the gear ratios in the transmission section of the tuning script. I successfully did that recently to limit the top speed of a bus I am building. Hopefully that helps.

4 Likes

Hi,

I don’t think it possible to solve your issue without modifying the drive script. You can try replacing the drive script with this modified version of the drive script instead. I modified it so that the chassis can’t go past the VehicleSeat “MaxSpeed” property. Note that this is based on the VehicleSeat velocity magnitude, not the MPH shown on the A Chassis UI.

Kind regards,
Yar890 (Group: Yar890 Studio)

Drive.lua (23.0 KB)

A more in-depth explanation can be found here: Cap A-Chassis Max Speed - #7 by AstrophsicaDev

5 Likes

Hello, I just wanted to say thank you so much for making this possible. I always wanted my cars in my game have a limit to the speed - as their script is messy I cannot really understand most of it (LOL). When my game is finished I will be sure to credit you for the script!

Thanks, Claasgreeneye.

1 Like

How to you get more plugins for Chassis? @keanwei01

I don’t think you understand how much this helps anyone with an A-Chassis. Thanks!

1 Like

Sorry to revive this topic… But I have found a easy way to do this. It works very well! Modify this to your liking.

-- Add this code in the Local Script named "Drive" or it will not work.
-- There's a while wait() loop so add this code there

-- If CurrentSpeed is more then MaxSpeed then
if (car.DriveSeat.Velocity.Magnitude > car.DriveSeat.MaxSpeed) then
        -- Slow down the car
		_GThrot = _Tune.IdleThrottle/500
	else
        -- Allow the car to speed up
        _GThrot = 1
	end
end

image

Navigate to the localscript “Drive” inside the A-chassis Interface and find the line containing “rev limiter”.

image

Replace the line

_spLimit = (_Tune.Redline+100)/(fFDr*_Tune.Ratios[_CGear+2])

with:

_spLimit = math.min(71-3,(_Tune.Redline-2900)/(fFDr*_Tune.Ratios[_CGear+2]))

The value 71-3 made me locking the car’s speed at a constant 73 km/h, while the redline value limits the engine rpm.

3 Likes

can you please show me how to make my suspension softer?

just make the cylindrical constraints max torque for the motors equal to game.Workspace.Gravity * massOfCar * topSpeed

l0l

There’s a plugin inside the A-chassis Tune’s plugin folder named [SS6] Dynamic Friction. I guess that’s the thing which alters the suspension?

let me test it out. btw its a plugin. not something which comes with a chassis.

this works but is there a reason that it tops at 30 (the max speed i put) on the vehicleseat but for a-chasiss speed text it only says 14 mph

Ok but my car is in parking mode when I enter? How do I disable this? Also how to make the car not in neutral when I enter the car?

It’s because it limits based on studs per second (vehicle seat velocity magnitude), whereas a chassis may display speed in mph/kph.

How do I make it stay at the top speed, instead of going down once it reaches the max?