Using :Lerp() on server lags parts behind

I have this basic script which is supposed to make the rig follow the player from behind :

local RunService = game:GetService("RunService")
local character = script.Parent.Parent.Parent

character:WaitForChild("HumanoidRootPart")


RunService.Heartbeat:Connect(function(d)
		script.Parent.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame:Lerp(character.HumanoidRootPart.CFrame * CFrame.new(2, 2, 4),d*10)
end)

This gives the following result :

https://gyazo.com/c09e755ea676a62966179c12b35d6fe0

At the current time, this script makes the rig “lag behind” and it’s not as snappy as I’d like. If this script is ran locally then hte movement is much quicker and there’s no lag, but then it won’t replicate. Is there any fix ? (I’m not looking to use welds or body movers, I tried tweens but with similar results)

1 Like

You don’t have to replicate it. Just render it all on each client.

Each client will see that there’s a rig following a player. You would then run the code snippet for every character.

1 Like

This doesn’t seem very efficient as I will often have to modify the offset of the rig’s position (when the player uses a move for instance). This would require to fire a remote multiple times to send the info to each client.

No. Have all the rigs on the client and animate all of it on the client only. No server intervention needed.

1 Like

As you can see, running the script locally prevents it from replicating to others, unless I’m missing something.

Make the rig on all clients. Then, animate all those rigs on every client. You’re only animating the rig on one client.

1 Like

By using this method, the problem falls back to my initial reply.
If let’s say a player presses a key which moves the cframe forward (not an animation, but modifying the lerp()), then I have to move the rig on every single other client too otherwise they won’t see the movement.

You can communicate that info to the server and have it fire to every client. The clients will then animate to that position.

Although this might be hard to implement, and using the server would be much easier, it’s good practice to do any and all animation-related things on the client. This ensures less server strain (equates to less ping at times), and better fluidity on the client.

You can do it all on the server, but then you’d expect latency like this to happen.