I am working on a cruise control plugin for the A-Chassis platform, and its not behaving as I want. When turned on it will jump to a random speed if the vehicle is in motion.
Here is the code, Local script:
script.Parent:WaitForChild("IsOn")
script.Parent:WaitForChild("Values")
ui = script:WaitForChild("WVD_Cruise_Control")
ui.Parent = script.Parent
ui.Visible = true
wait()
local dashlight = ui.On
local mouse = game.Players.LocalPlayer:GetMouse()
local setspeed = script.Parent.Values.CC_Speed.Value
local cfWRot = CFrame.Angles(math.pi/2,-math.pi/2,0)
local cfYRot = CFrame.Angles(0,math.pi,0)
mouse.KeyDown:connect(function(key)
if key == "v" then
if script.Parent.Values.CruiseControl.Value == false then
script.Parent.Values.CruiseControl.Value = true
setspeed = math.floor(script.Parent.Car.Value:FindFirstChild("DriveSeat").Velocity.Magnitude)
else
script.Parent.Values.CruiseControl.Value = false
end
end
if key == "]" then
setspeed += 1
print(setspeed)
end
if key == "[" then
setspeed -= 1
print(setspeed)
end
if key == "s" then
if script.Parent.Values.CruiseControl.Value == true then
script.Parent.Values.CruiseControl.Value = false
end
end
end)
while wait(0) do
if script.Parent.Values.CruiseControl.Value == true then
dashlight.Visible = true
for _,v in pairs(script.Parent.Car.Value:FindFirstChild("Wheels"):GetChildren()) do
if v.Name == "FL" or v.Name == "RL" then
--Straight Outta A-Chassis
local Ref=(CFrame.new(v.Position-((v.Arm.CFrame*cfWRot).lookVector),v.Position)*cfYRot).lookVector
local aRef=1
v:FindFirstChild("#AV").AngularVelocity = -Ref*aRef*setspeed
v:FindFirstChild("#AV").MaxTorque = Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*9999
elseif v.Name == "FR" or v.Name == "RR" then
--Straight Outta A-Chassis
local Ref=(CFrame.new(v.Position-((v.Arm.CFrame*cfWRot).lookVector),v.Position)*cfYRot).lookVector
local aRef=-1
v:FindFirstChild("#AV").AngularVelocity = -Ref*aRef*setspeed
v:FindFirstChild("#AV").MaxTorque = Vector3.new(math.abs(Ref.x),math.abs(Ref.y),math.abs(Ref.z))*9999
end
end
else
dashlight.Visible = false
end
end```