I’m trying to create a simple car script, and it works really well, unless the server has any sort of lag in it. The higher the ping, the longer it take for the car to turn.
For instance, if my ping is normal, around 70 ms, the car turns the way it’s supposed to-- when you hit the button.
But if the ping is above ~175, you can start noticing the steering not responding right away when you hit the buttons to do so.
The code is as follows:
`wait()
function drive(Property)
local seat = script.Parent
local car = seat.Parent
local drive = car:FindFirstChild(“Drive”)
local base = car:FindFirstChild(“Base”)
local RPs = car.Parent.Config.MaxSpeed.Value
local leftDrive = drive.Left
local rightDrive = drive.Right
local maxSpeed = math.rad(360*RPs)
local torque = car.Parent.Config.Torque.Value
leftDrive.MotorMaxTorque = torque
rightDrive.MotorMaxTorque = torque
if Property == "Throttle" then
leftDrive.AngularVelocity = maxSpeed * seat.Throttle
rightDrive.AngularVelocity = -maxSpeed * seat.Throttle
end
if Property == "Steer" then
if seat ~= nil and base ~= nil and seat.Steer == 0 then
base.Turn.angularvelocity = Vector3.new(0, 0, 0) -- leave alone
elseif seat ~= nil and base ~= nil and seat.Steer ~= 0 and seat.Velocity.Magnitude > 10 then
base.Turn.angularvelocity = Vector3.new(0, (-seat.Steer), 0) * (((-1.1 * -1.015^-seat.Velocity.Magnitude)) + 0.4)
elseif seat ~= nil and base ~= nil and seat.Velocity.Magnitude < 10 then
base.Turn.angularvelocity = Vector3.new(0, 0, 0) -- leave alone
end
end
end
script.Parent.Changed:Connect(drive)`
What is causing the steering to lag so far behind when the server’s/player’s ping is high? Is there a good way to fix this?