Server Input Lag

I’ve been working on a bumper cars game, but I’ve been having issues with input lag and can’t figure out how to fix it.

There isn’t really any specific code I can show, but basically what happens is:

  1. Input is recieved by ContextActionService, which then runs a function that sends a
    RemoteEvent to the server.
  2. When the Server gets the event, it sets that player’s variables (up, down, left, and right) to either true or false (depending on whether the player pressed or let go of that button).
  3. The server changes the player’s turn/speed variables depending on which button was pressed
  4. An infinitely running loop changes the car’s BodyGyro and BodyVelocity depending on the player’s turn and speed variables.

Originally, while working on the car engine, I tried using a BodyAngularVelocity object for the chassis, which didn’t end up working due to problems with rotating the car on its local axis. I did make a few posts about it, but they were either ignored or I couldn’t find a solution.

I believe the problem is coming from somewhere in the server. This is because even if the server isn’t catching the player’s input, the car shouldn’t be lagging while the button hasn’t been released. e.g. If I have the W key pressed, the car might lag and stop while I am driving it. Yet since it hasn’t been released, my up variable is still set to true. If I haven’t been clear enough, let me know and I’ll try to explain it better :laughing:

1 Like

Just to clarify, is the lag you’re talking about on the car moving (i.e. it is visibly shaking while changing positions) or is it because of latency where the server is not changing the movement value for the car fast enough?

1 Like

The car isn’t moving when its BodyMovers and variables should be moving it.

1 Like

You made sure everything is unanchored and welded properly?

1 Like
Physics.weld = function(player)
	local car = _G.stats.players[player.Name].car
	if car.PrimaryPart then
		car.PrimaryPart.Anchored = false
		for _, part in pairs(car:GetDescendants()) do
			if part:IsA('BasePart') and part ~= car.PrimaryPart then
				part.Anchored = false
				part.Massless = true
				local newWeld = Instance.new("Weld")
				newWeld.Parent = part
				newWeld.Part0 = part
				newWeld.Part1 = car.PrimaryPart
				newWeld.C0 = part.CFrame:Inverse()
				newWeld.C1 = car.PrimaryPart.CFrame:Inverse()
			end
		end
	end
end

The car moves. It just lags.

1 Like

Can you provide a video so I have a better understanding of what’s happening?

1 Like

There’s nothing to record, it’d just look like normal lag. I’d have to join a server with at least 2 other players in it anyway, or the lag isn’t really noticeable.

1 Like

I can’t help you much in this scenario then. My advice based on what you’ve said is to remove server input control entirely as that will lag regardless of what you do. The client should be handling all input and adjusting accordingly. The server should then update those values with a tween (or something similar) to compensate for latency.

Quick question did you set the network ownership of those bumper cars to the current driver? that usually has some adverse effects if not done correctly

The lag could be due to this infinite loop being too fast.
Correct me if i am wrong.

The true question is why is he listening for input when the roblox vehicle seat has steer and throttle already implemented and you could listen for changes in those making the load a whole lot less.

EDIT: he could also set network ownership of the vehicle and handle all the forces etc on the client because the client essentially ‘owns’ that vehicle making the server only handle things it needs to

This is a customized car system. I am not using a vehicle seat. I’ll try the network ownership idea though :+1:

That in my opinion is a terrible idea if you make the vehicles owner the client. Why that is a terrible idea is because ROBLOX’s Physics Engine, ROBLOX does not verify physics calculations meaning if the client has network ownership over the vehicle the client can exploit that and teleport all the vehicles out of the map or something like that breaking the game essentially, now you could verify the position of each vehicle is inside the map but you are already having issues with lag so that would probably cause more lag. Basically anything that’s owner is the client or that is unanchored can be controlled by the client. Well if you are specifically setting it to that client and not all of them you don’t have to worry cause they can only mess with there car.

Anything that shows up in the game is in the client- meaning the cars are already in the client anyway, and therefore can be exploited even without network ownership. Keeping it on the server isn’t going to help with that problem.

Ok what I am trying to say is if the cars are unanchored or something then the client can move them and it will replicate to other clients cause they have network ownership over it, but if the server has network ownership over something and the client moves it it will only replicate to them. But if you specifically set network ownership to a certain client only they can move it.

Exploiting the position of the car isn’t going to be much of a problem anyway, partly because the character’s network owner is already the client, and also because if a car did spawn out of the map, all it could do would be drive out and fall until it is destroyed, then respawns.

Ok because I thought you were making all the car unanchored or something which would make it so the client could move all the cars to where they wanted. My bad.

The car is unanchored. It uses Body Movers.

Make it so the server has ownership over it otherwise a client can teleport all the bumper cars out of the map thus breaking the game.

It will not break the game. The cars will respawn. Please stop making a big deal about this when it’s not even a problem. If I need help with exploits I will make a new post for that.