Higher pings = Higher delay time in controls such as steering. Works perfectly fine and smooth in studio.
local seat = script.Parent.VehicleSeat
local engine = script.Parent.Body:WaitForChild("Engine")
local motors = script.Parent.Motors:GetChildren()
local servos = script.Parent.Servos
wait(1)
engine.Anchored = false
local speed = 0
---//Main
while wait() do
if seat.Throttle == 0 then
if speed > 1 then
speed = speed - 1
elseif speed > 0 then
speed = 0
elseif speed < -1 then
speed = speed + 1
elseif speed < 0 then
speed = 0
end
else
speed = speed + seat.Throttle
speed = speed > seat.MaxSpeed and seat.MaxSpeed or speed < -seat.MaxSpeed and -seat.MaxSpeed or speed
end
for _, motor in pairs(motors) do
motor.AngularVelocity = -seat.Throttle * 110
end
servos.Right.TargetAngle = -seat.Steer * 20
servos.Left.TargetAngle = -seat.Steer * 20
end
local VehicleSeat = script.Parent:WaitForChild("VehicleSeat")
VehicleSeat.Changed:Connect(function(prop)
if prop == "Occupant" then
local humanoid = VehicleSeat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player then
VehicleSeat:SetNetworkOwner(player)
end
else
VehicleSeat:SetNetworkOwnershipAuto()
end
end
end)

3 comments
Everything located in a server-side script
Why are you abusing the while loop like that?
Not sure if there are any other alternatives