What do you want to achieve? I want to cap the speed at the value of the MaxSpeed variable(prevent it from going any faster)
What is the issue? If I go above the max speed _GThrot will stay at 0 unless I release W and then press it again and I’m not sure how to fix that
What solutions have you tried so far? I could not find and can’t think of any solutions
Code(in Drive LocalScript):
local MaxSpeed = 60 -- ~30 mph
function CapMaxSpeed()
if car.DriveSeat.Velocity.Magnitude > MaxSpeed then
_GThrot = 0
end
end
game["Run Service"].Stepped:connect(function()
-- Other A-Chassis stuff above --
CapMaxSpeed()
end)
I misunderstood your question. Try making the script repeat wait() (in any interval) until the Magnitude is less than or equal to the MaxSpeed.
local MaxSpeed = 60 -- ~30 mph
function CapMaxSpeed()
if car.DriveSeat.Velocity.Magnitude > MaxSpeed then
_GThrot = 0
repeat wait() until car.DriveSeat.Velocity.Magnitude <= MaxSpeed --set wait() to any interval (Heartbeat, renderstep ,etc.)
_GThrot = --speed here
end
end
game["Run Service"].Stepped:connect(function()
-- Other A-Chassis stuff above --
CapMaxSpeed()
end)
Try using this snippet, tell me if it helps your issue.
TLDR; Download the Lua script attached to this and replace the “drive” script with my version. Set MaxSpeed in the VehicleSeat properties. The “drive” script is located at: A-Chassis Tune > A-Chassis Interface > Drive Drive.lua (23.0 KB)
I had this exact issue and managed to fix it. The reason for your issue is that the drive script only changes _GThrot and _GBrake when an input has begun (Such as a keyboard key press), changed or released. This means holding the input button is not detected. You can see this below:
The solution I came up with was to detect when Throttle and Brake input was processed (around line 170) and save the current status of the input. For example, I created a new variable called _ThrotActive and set it to true when the throttle input is active. When throttle input has ended, I set it to false. This variable can then be used to reset throt back to its current state after the car velocity magnitude is lower than the car max speed.
I’ve attached a copy of my modified A Chassis MaxSpeed limiter Drive script to this reply. Feel free to swap and use this script instead.
I’ve had a look at the script and noticed that the gamepad inputs are processed lower in the script. Adding the following might fix the issue. Be aware that I have not tested this new code: