Hey Roblox developers,
I recently wrote a new simple method that seems to significantly reduce latency in my game, but I’m having trouble understanding why it even works in the first place.
Server Script:
game.ReplicatedStorage.Position.OnServerEvent:Connect(function(plr, pos, rot)
game.ReplicatedStorage.Position:FireAllClients(plr, pos, rot)
end)
LocalScript (quick preview w/o the if conditions):
local runService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
game.ReplicatedStorage.Position.OnClientEvent:Connect(function(player, pos, rot)
if player ~= plr then
player.Character.HumanoidRootPart.Anchored = true
player.Character.HumanoidRootPart.CanCollide = false
player.Character.HumanoidRootPart.CFrame = pos
end
end)
runService.Heartbeat:Connect(function()
local char = plr.Character
game.ReplicatedStorage.Position:FireServer(char.HumanoidRootPart.CFrame, char.HumanoidRootPart.CFrame.LookVector)
end)
By spamming the server with :FireServer(), the player’s experience seems to improve greatly in my game. Which sounds counterintuitive.
Does anyone know why the player characters sync better when using the method compared to not using it?
I’m guessing performance improves due to the other player’s Rootpart being anchored (and probably minor improvements due to cancollide being off).
However this is most likely not free! You should check your network send and receive before, and after the change.
I’m pretty sure what you’re doing has a (big) effect on network recv. Might or might not be bad, depending on how much your game uses up by default.
1 Like
Yeah, the network send/receive is the first thing I looked at after implementing this feature. In a full server of 8 players in my game, the network send is around 16 kb/s and network receive at 36 kb/s, I definitely see it as a win.
I would actually recommend using this if the game doesn’t have a lot of players per server and doesn’t use up a lot of network send/recv by default. I even made a test place where you can sword fight with high walkspeed and it just seems flawless to me.
1 Like
Do you happen to know what it was like before the change?
1 Like
Looking at my old medal clips, network recv averaged 30 kb/s and network send was around 12 kb/s for the same amount of players.
1 Like
afaik humanoids update at 20 hz which is pretty bad and the inbetweens are interpolated on each client. what ur probably doing is getting rid of most that “in between” period and sending everyone the newest possible position immediately. especially if the frames on which the remote event fires happen after the ones on which the humanoid updates. cause remote events can only be called 20 times a second as well from what i know unless that can be mitigated somehow