How to change roblox car max speed?

I just used roblox created vehicle, but I am having trouble setting the maximum speed. I have tried various methods but have not been successful. Can anyone assist me in adjusting the car’s top speed?

The car model:https://create.roblox.com/marketplace/asset/6418230807/Police-Car
copcar

Chassis:

local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local ProximityPromptService = game:GetService("ProximityPromptService")

local CarValue = script:WaitForChild("CarValue")
local Car = CarValue.Value

local RAW_INPUT_ACTION_NAME = "VehicleChassisRawInput"
local EXIT_ACTION_NAME = "VehicleChassisExitVehicle"

--Get modules

--Initialize Chassis
local ScriptsFolder = Car:FindFirstChild("Scripts")
local Chassis = require(ScriptsFolder:WaitForChild("Chassis"))
Chassis.InitializeDrivingValues()
Chassis.Reset()

--Set up gui - has its own class
local VehicleGui = require(script.Parent:WaitForChild("LocalVehicleGui")).new(Car)
VehicleGui:Enable()
VehicleGui:EnableDriverControls()
VehicleGui:EnableSpeedo()

local Keymap = require(ScriptsFolder.Keymap)
local _rawInput = Keymap.newInputTable()
local LocalVehicleSeating = require(ScriptsFolder.LocalVehicleSeating)

local function _clearInput()
	for k, v in pairs(_rawInput) do
		_rawInput[k] = 0
	end
end

--Objects
local DriverSeat = Chassis.driverSeat

local function unbindActions()
	ContextActionService:UnbindAction(RAW_INPUT_ACTION_NAME)
	ContextActionService:UnbindAction(EXIT_ACTION_NAME)
end

local function onExitSeat(Seat)
	unbindActions()
	_clearInput()
	ProximityPromptService.Enabled = true
	LocalVehicleSeating.DisconnectFromSeatExitEvent(onExitSeat)
	script.Disabled = true
end
LocalVehicleSeating.OnSeatExitEvent(onExitSeat)

--Disable script if car is removed from workspace
Car.AncestryChanged:Connect(function()
	if not Car:IsDescendantOf(Workspace) then
		unbindActions()

		LocalVehicleSeating.ExitSeat()
		LocalVehicleSeating.DisconnectFromSeatExitEvent(onExitSeat)
		-- stop seated anim
		--print("car removed from workspace")

		script.Disabled = true
		ProximityPromptService.Enabled = true
	end
end)

local function exitVehicle(action, inputState, inputObj)
	if inputState == Enum.UserInputState.Begin then
		LocalVehicleSeating.ExitSeat()
		-- stop seated anim
	end
end

local function _updateRawInput(_, inputState, inputObj)
	local key = inputObj.KeyCode
	local data = Keymap.getData(key)
	
	if not data then 
		return
	end
	
	local axis = data.Axis
	local val = 0
	
	if axis then
		val = inputObj.Position:Dot(axis)
	else
		val = (inputState == Enum.UserInputState.Begin or inputState == Enum.UserInputState.Change) and 1 or 0
	end
	
	val = val * (data.Sign or 1)
	
	_rawInput[key] = val
	
	if data.Pass then
		return Enum.ContextActionResult.Pass
	end
end

local function _calculateInput(action)
	-- Loop through all mappings for this action and calculate a resultant value from the raw input
	local mappings = Keymap[action]
	local val = 0
	local absVal = val
	
	for _, data in ipairs(mappings) do
		local thisVal = _rawInput[data.KeyCode]
		if math.abs(thisVal) > absVal then
			val = thisVal
			absVal = math.abs(val)
		end
	end
	
	return val
end

ContextActionService:BindAction(
	EXIT_ACTION_NAME,
	exitVehicle,
	false,
	Keymap.EnterVehicleGamepad,
	Keymap.EnterVehicleKeyboard
)

ContextActionService:BindActionAtPriority(
	RAW_INPUT_ACTION_NAME,
	_updateRawInput,
	false,
	Enum.ContextActionPriority.High.Value,
	unpack(Keymap.allKeys()))

--Interpret input
local function getInputValues()
	if UserInputService:GetLastInputType() ~= Enum.UserInputType.Touch then
		---Let the control module handle all none-touch controls
		script.Throttle.Value = _calculateInput("Throttle") - _calculateInput("Brake")
		script.Steering.Value = _calculateInput("SteerLeft") + _calculateInput("SteerRight")
		script.HandBrake.Value = _calculateInput("Handbrake")

	else --The vehicle gui handles all the touch controls
		script.Throttle.Value = VehicleGui.throttleInput
		script.Steering.Value = VehicleGui.steeringInput
		script.HandBrake.Value = VehicleGui.handBrakeInput
	end
end

ProximityPromptService.Enabled = false

-- Driver Input Loop --
while script.Parent ~= nil do
	--Update throttle, steer, handbrake
	getInputValues()

	local currentVel = Chassis.GetAverageVelocity()

	local steer = script.Steering.Value
	Chassis.UpdateSteering(steer, currentVel)

	-- Taking care of throttling
	local throttle = script.Throttle.Value
	script.AngularMotorVelocity.Value = currentVel
	script.ForwardVelocity.Value = DriverSeat.CFrame.LookVector:Dot(DriverSeat.Velocity)
	Chassis.UpdateThrottle(currentVel, throttle)

	-- Taking care of handbrake
	if script.HandBrake.Value > 0 then
		Chassis.EnableHandbrake()
	end
	wait()
end

2 Likes

It is not part of the script to change it, it is rather part of the VehicleSeat, a property of it.

No, I do not think that is the problem, It only has door hinges and a proximity prompt nothing else

You have to change the script.Throttle.Value, this is not quite the scripting issue more of a settings issue. :sweat_smile:

I do not know, whatever I change does not affect speed, I changed everything but did not quite work out, Can you just tell me step by step what to change, please?

Maybe you can change this.
Either search for the function or just write

local currentVel = Chassis.GetAverageVelocity() * 5
1 Like

There is an attribute on the car, Click the model, Scroll down on the properties and should see it.

It is not just a jeep car from roblox it is a new cop car from roblox.

Can you provide me the link? So I can take a look

image

6 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.