Park a car in a-chassis

I’m trying to add a button to park an a-chassis car and keep it parked regardless of if the driver presses P. The problem is, I can’t find any way to do this. I’ve tried adding parts and anchoring them, anchoring the wheels, but the car body will stay where its at.

For a bit more context, the car suspension gets tweened but I want that to happen while the car is parked. Anchoring the wheels doesn’t work, because the car body will start to glitch because it’s also anchored. I’m wanting to know if there’s a way to actually put the car in park, not just anchor the parts.

1 Like

assuming you meant that you want the button to override the preexisting parking logic, what does the function connected to pressing P do when in order to park the car?

1 Like

That’s what I’ve been trying to figure out, but the only thing I can find in the “Drive” script is this:

--Toggle PBrake
			elseif _IsOn and  input.KeyCode ==_CTRL["ContlrPBrake"] or (_MSteer and input.KeyCode==_CTRL["MousePBrake"]) or ((not _MSteer) and input.KeyCode==_CTRL["PBrake"]) then
				if input.UserInputState == Enum.UserInputState.Begin then
					_PBrake = not _PBrake
				elseif input.UserInputState == Enum.UserInputState.End then
					if car.DriveSeat.Velocity.Magnitude>5 then
						_PBrake = false
					end
				end

I can’t find any info on how to pull off something like this, not even in the README file.

okay, can you look into the _CTRL table to see which KeyCode is assigned to “ContlrPBrake” just to make sure this is the right snippet?

it’s P in the tune module script

okay then, there should be a while loop that looks something like this:

while wait() do
 if _PBrake == true then
  --code
 end
end

or

while _PBreak do
 --code
end

can you try to find that?

The only loop I could find was this in the Drive script:

while wait() do
...
script.Parent.Values.PBrake.Value = _PBrake
...
end

But I also found this, I think this might be how the PBrake is handled but I’m not sure:

if _PBrake and ((_Tune.Config ~= "FWD" and (((v.Name=="FL" or v.Name=="FR") and car.DriveSeat.Velocity.Magnitude<20) or ((v.Name=="RR" or v.Name=="RL") and car.DriveSeat.Velocity.Magnitude>=20))) or (_Tune.Config == "FWD" and (v.Name=="RR" or v.Name=="RL"))) then
				--PBrake
				v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*PBrakeForce
				v["#AV"].angularvelocity=Vector3.new()
			else

okay, now you have to find what script.Parent.Values.PBrake.Value, probably another while loop or a function for trying to move the vehicle, be careful though, it might be stored as a variable instead of being directly referenced, in that case you have to find said variable

one second I’ll take a look at it

what are Ref and v in this case?

v is each wheel and #AV is the AngularVelocity parts, and Ref is this:

local Ref=(CFrame.new(v.Position-((v.Arm.CFrame*CFrame.Angles(math.pi/2,-math.pi/2,0)).lookVector),v.Position)*CFrame.Angles(0,math.pi,0)).lookVector

okay then, try to comment out the two lines

v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*PBrakeForce
v["#AV"].angularvelocity=Vector3.new()

and see if the car still breaks while pressing P

Okay, I commented them out, and that is what controls the parking brake.

then its time to do what programmers do best (pasting other people’s code without understanding what it does)

if you don’t have a button then I can explain how to make one in detail, but if you do, create a click detector in it, then put a script inside of it (or not, it just has to be connected to the click detector like this:

button.ClickDetector.MouseClick:Connect(function()
end)

then get the wheels of the car (I assume they’re stored in a module or something because they’re actually dictionaries? so in that case require the module and do whatever the drive code did)

then just paste the definition of Ref since you have all of the variables you need already

and lastly add the if check along with all of the _Tune.Config stuff (I assume another module) and paste the two lines of code into it and test if it works

this isn’t the best way of doing it but honestly the code is really hard to read and as long as you wont change much behavior for the wheels or the parking break itself I think you should be good

I copied and pasted the code into a function, but for some reason the car sometimes gets shot forward for a second and you can still drive it. This is the function:

function parkCar()
	for i,v in pairs(car.Wheels:GetChildren()) do
		local Ref=(CFrame.new(v.Position-((v.Arm.CFrame*CFrame.Angles(math.pi/2,-math.pi/2,0)).lookVector),v.Position)*CFrame.Angles(0,math.pi,0)).lookVector

		v["#AV"].maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*PBrakeForce
		v["#AV"].angularvelocity=Vector3.new()
	end
end

and this is what happens when I try and run that function:

I’m pretty sure that you should use ipairs instead because getchildren() returns an array and not a dictionary (I broke a lot of scripts that way in the past)
from what I know the loop doesn’t get iterated over at all if you call the wrong method on it

Still gives me the same result

in that case the only thing I can think of is that there’s more logic related to it that causes parking to work but doesn’t need to be removed in order for parking to break, if that’s not the case I am honestly out of ideas

Yeah I can’t think of any other solutions either, I may just resort to anchoring the wheels again although it’s kinda broken. Thank you so much for your help though

you’re welcome, but dont worry maybe someone else will eventually find a solution

I found a VERY scuffed solution, but it works for me.

In my button script, I rename each of the BodyAngularVelocities in the wheels to “parked,” which the script doesn’t recognize. And to prevent the drive script from completely breaking, I changed lines 536 and 537 from v["#AV"] to v:WaitForChild("AV").

Here is my park function:

local wheels = car.Wheels:GetChildren()
function parkCar(val)
	if val == true then
		for i, v in wheels do
			v["#AV"].Name = "parked"
		end
	else
		for i, v in wheels do
			v.parked.Name = "#AV"
		end
	end
end

and lines 536 and 537 in the Drive script are:

v:WaitForChild("#AV").maxTorque=Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*_OutTorque*(1+(v.RotVelocity.Magnitude/60)^1.15)*throt*tqTCS*diffMult*on
v:WaitForChild("#AV").angularvelocity=Ref*aRef*spLimit*dir
1 Like