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):
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
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.
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.
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!
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