How to prevent other players from "lagging behind"? (similar to how you see in Jailbreak)

So, using some posts around the DevForum, I’ve managed to come up with a script that smoothly, and at any speed, keeps your character on a tweening model. However, I’m stumped on how to make the other players also smoothly be moving with you on your client, and can’t find a post that may help.

You can see my issue from this: See the video here

Here is my client code that keeps the player moving with the model. It should be noted that I have simplified it for your reading so that the character will move with the model, regardless of whether you are physically on it or not, as that shouldn’t be relevant:

--[Services]--
local players = game:GetService("Players")
local runService = game:GetService("RunService")


--[Assets]--
local player = players.LocalPlayer
local camera = game.Workspace.CurrentCamera


--[Variables]--
local lastCFrame = nil

local heartbeatConnection


--[Code]--
heartbeatConnection = runService:BindToRenderStep("planeCFraming", 1, function()
	task.defer(function()
		local character = player.Character
		if not character then return end
		
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
		if not humanoidRootPart then return end
		
		local modelPrimaryPart = player:FindFirstChild("modelPrimaryPart") --This just references the primary part of the model (this value is set by the server).
		if not modelPrimaryPart or not modelPrimaryPart.Value then return end
		
		if not lastCFrame then
			lastCFrame = modelPrimaryPart.Value.CFrame
		end
		
		local instanceCFrame = modelPrimaryPart.Value.CFrame
		local relativeCFrame = instanceCFrame * lastCFrame:Inverse() --This calculates the distance between the previous position and new position of the primary part
		lastCFrame = instanceCFrame
		
		humanoidRootPart.CFrame = relativeCFrame * humanoidRootPart.CFrame --Move the character by what we just calculated
		camera.CFrame = relativeCFrame * camera.CFrame
	end)
end)

I have already tried to make each client send the server its position, and allow the other clients to read that and set the other player’s positions locally, however, the character jitters between where what I think is each character being replicated and the correct position that I am sending it. Maybe is there a way that I can prevent the automatic replication?

Any help is appreciated; I have already tried looking around but no luck. Feel free to send other post links if you think that I’ve missed one.

(Edit: If you’ve ever played Jailbreak, my exact issue is like when you get on the train or plane robbery and when it speeds up, you start to see the other players trailing behind)

1 Like