Cap A-Chassis Max Speed

  1. 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)

  2. 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

  3. 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)

A-Chassis: https://www.roblox.com/library/426082613/A-Chassis-6-52S2-Kit

3 Likes

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.

2 Likes

That’s the exact same code as I have now except you used >= instead of = which isn’t the issue anyway and no, it didn’t help my issue

Read the comments, and try following what I suggested.
I had to make edits.
If that doesn’t work, doing away with the function will remove the limit.

I don’t want to remove the limit, I want to prevent the car from going over the Max Speed

1 Like

I fixed the error. Please re-read the message. I didn’t notice that portion of your question.

3 Likes

Hi,

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:

    	UserInputService.InputBegan:connect(DealWithInput)
    	UserInputService.InputChanged:connect(DealWithInput)
    	UserInputService.InputEnded:connect(DealWithInput)

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.

Kind regards,
Yar890 (Group: Yar890 Studio)

13 Likes

Sorry to revive the thread however my players are reporting that controller support is broken. Any fixes?

Hi @MeatLandCruiser,

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:

1 Like