Vehicle responding to input slow (Input Lag?)

I recently redid the script to make it assign NetworkOwnership, it appeared that everything was running fine for a couple of hours - and randomly the input lag begins again.

Here is the current script:

Server Script:

script.Parent.EngineOff:Play()
local speed = 0
local accel = 2--originally 2
local TimeTillDestroy = 500

local timeSincelastOccupant = 0

local FLW = script.Parent.Parent.FrontLeftWheel
local FRW = script.Parent.Parent.FrontRightWheel
local BLW = script.Parent.Parent.BackLeftWheel
local BRW = script.Parent.Parent.BackRightWheel



-----


while wait() do
	if script.Parent.Occupant then


		local humanoid = script.Parent.Occupant

		local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)

		if player then
			script.Parent:SetNetworkOwner(player)
		end

		if speed > 10 and script.Parent.Occupant.Parent.HumanoidRootPart.Velocity.magnitude < speed then

			speed = script.Parent.Occupant.Parent.HumanoidRootPart.Velocity.magnitude
		end
		timeSincelastOccupant = 0
	else
		
			if timeSincelastOccupant > TimeTillDestroy then
				script.Parent.Parent:Destroy()
			end
					script.Parent:SetNetworkOwnershipAuto()
					speed = 0
					timeSincelastOccupant = timeSincelastOccupant + 0.2
	end
	if script.Parent.Throttle == 1 then
		FLW.HingeConstraint.AngularVelocity = speed
		FRW.HingeConstraint.AngularVelocity = speed
		BLW.HingeConstraint.AngularVelocity = -speed
		BRW.HingeConstraint.AngularVelocity = -speed
		if speed < 0 then
			speed = speed+accel
		elseif speed < 35 then--originally 35
			speed = speed+accel/5
		end
		script.Parent.Parent.CarModel.BackLights1.Material = Enum.Material.SmoothPlastic
		script.Parent.Parent.CarModel.BackLights1.BackLight.Enabled = false
	elseif script.Parent.Throttle == -1 then
		FLW.HingeConstraint.AngularVelocity = speed
		FRW.HingeConstraint.AngularVelocity = speed
		BLW.HingeConstraint.AngularVelocity = -speed
		BRW.HingeConstraint.AngularVelocity = -speed
		if speed >= 0 then
			speed = speed-accel
		elseif speed > -15 then
			speed = speed-accel/5
		end
		script.Parent.Parent.CarModel.BackLights1.Material = Enum.Material.Neon
		script.Parent.Parent.CarModel.BackLights1.BackLight.Enabled = true
	else
		FLW.HingeConstraint.AngularVelocity = speed
		FRW.HingeConstraint.AngularVelocity = speed
		BLW.HingeConstraint.AngularVelocity = -speed
		BRW.HingeConstraint.AngularVelocity = -speed
		if speed > 0 then
			speed = speed-accel
		elseif speed <= 1 and speed >= -1 then
			speed = 0
		end
		script.Parent.Parent.CarModel.BackLights1.Material = Enum.Material.Neon
		script.Parent.Parent.CarModel.BackLights1.BackLight.Enabled = true
	end

	script.Parent.EngineOff.PlaybackSpeed = 1+math.abs(speed)/20


	script.Parent.Parent.FrontRightSteer.HingeConstraint.TargetAngle = script.Parent.Steer*17	
	script.Parent.Parent.FrontLeftSteer.HingeConstraint.TargetAngle = script.Parent.Steer*17

	if game.Lighting.ClockTime > 6.5 and game.Lighting.ClockTime < 17.5 then
		script.Parent.Parent.CarModel.HeadLights.Material = Enum.Material.SmoothPlastic
		script.Parent.Parent.CarModel.HeadLights.HeadLight.Enabled = false
	else
		script.Parent.Parent.CarModel.HeadLights.Material = Enum.Material.Neon
		script.Parent.Parent.CarModel.HeadLights.HeadLight.Enabled = true
	end

end

This is the only script that makes the vehicle function the way it does, I’m not the most experienced with vehicle scripting by any means.

To experience the “input lag” - you can feel free to check it out in our game, there is car spawns located all around the map:

https://www.roblox.com/games/6425690762/Springbrook-RP-BETA#

Even if the physics of the vehicle is set to the client, there’s no point if the input to physics is still being controlled from the server as you are still reading from the input of the vehicle seat from the server side perspective.

The input is still waiting to be transferred from client to server in order to change the input throttle property on the seat in the server hence lag since it’s in a server script.

The simple and easy solution for a beginner would be to copy and paste this script into a local script. Then upon seating using the seats Get Occupant signal to give the player the local script in a suitable place where it’ll run like PlayerGui.

The variables will also have to be redirected which can be done by getting the players seat part which you get by getting the players character humanoid through player.Character and Humanoid | Documentation - Roblox Creator Hub to which you can do the script.Parent from there.

1 Like