Vehicle Script seems very glitchy for me

I have a vehicle control script that uses VehicleSeat inputs.
However when I play I notice once in a while that the throttle or steering input seems to ‘hang on’ for a second or so when the keyboard inputs are stopped which is very noticeable.

I’ve also been having internet speeds slowing down on my computer so I’m not sure if that’s a factor, but this is also happening while testing in Studio, which from what I understand doesn’t require an internet connection.

I’ve tried putting each input check inside it’s own If check instead of the if then else checks, but it doesn’t seem to make a difference.

The med variable is there for fine tuning with different vehicles

If you have any better suggestions I’d appreciate your input about my inputs :wink:

local seat = script.Parent.VehicleSeat
local L = script.Parent.Left.HingeConstraint
local R = script.Parent.Right.HingeConstraint
local max = 80
local med = 50
local min = 15

local function control()
	if seat.Occupant == nil then 
		seat.Steer = 0
		seat.Throttle = 0
	end
	if seat.Steer == 0 or seat.Steer == nil and seat.Throttle == 0 or seat.Throttle == nil then  --stop 
		R.AngularVelocity = 0 		
		L.AngularVelocity = 0 		
	end
	if seat.Steer == 0 and seat.Throttle == 1 then --forwards
		L.AngularVelocity = max		
		R.AngularVelocity = -max		
	elseif seat.Steer == 0 and seat.Throttle == -1 then --backwards
		L.AngularVelocity = -max		
		R.AngularVelocity = max	
	end
------------------------------------------------------------------------------------------
	if seat.Steer == 1 and seat.Throttle == 1 then --forwards and turn right
		L.AngularVelocity = max
		R.AngularVelocity = -min
	elseif seat.Steer == 1 and seat.Throttle == 0 then --turn right
		L.AngularVelocity = min
		R.AngularVelocity = min
	elseif seat.Steer == 1 and seat.Throttle == -1 then --backwards and turn right
		L.AngularVelocity = -max
		R.AngularVelocity = min
	end
------------------------------------------------------------------------------------------
	if seat.Steer == -1 and seat.Throttle == 1 then --forwards and turn left
		L.AngularVelocity = min 
		R.AngularVelocity = -max 
	elseif seat.Steer == -1 and seat.Throttle == 0 then --turn left
		L.AngularVelocity = -min
		R.AngularVelocity = -min
	elseif seat.Steer == -1 and seat.Throttle == -1 then --backwards and turn right
		L.AngularVelocity = -min
		R.AngularVelocity = max
	end
end
	
seat.Changed:Connect(control)
3 Likes

So 9 days without a single reply?

It does, I’ve tested it before.
As for the script, it’s a bit messy, but I don’t see any reason why it shouldn’t work. I’ve never used VehicleSeats, but from what I can tell from your post it still works, just with lag.
To test if it’s wifi issues, try attaching a RemoteEvent to a UI button click and print something, and see if it takes a second like with the car controls

1 Like