I have a very barebones character replication system that I am working on because it is for a game that I plan to implement custom replication for. I’ve heard about using a replication buffer system and how it actually works, basically a system that allows me to use future positions of the character that I can use that if a small fluctuation in ping occurs and other stuff.
I am mainly looking for advice on how I can implement this, this is what my current system looks like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local replicateCharacterRemoteEvent = ReplicatedStorage.Events.RemoteEvents.ReplicateCharacter
local localPlayer = Players.LocalPlayer
local humanoidRootPart
local UPDATE_RATE = 0.05
task.spawn(function()
while task.wait(UPDATE_RATE) do
if humanoidRootPart then
replicateCharacterRemoteEvent:FireServer(humanoidRootPart.Position, humanoidRootPart.orientation, humanoidRootPart.AssemblyLinearVelocity)
end
end
end)
localPlayer.CharacterAppearanceLoaded:Connect(function(character)
if character.HumanoidRootPart then
humanoidRootPart = character.HumanoidRootPart
if humanoidRootPart.Anchored == true then
humanoidRootPart.Anchored = false
end
humanoidRootPart:GetPropertyChangedSignal("Anchored"):Connect(function()
if humanoidRootPart.Anchored == true then
humanoidRootPart.Anchored = false
end
end)
end
end)
replicateCharacterRemoteEvent.OnClientEvent:Connect(function(player, position, orientation, assemblyLinearVelocity)
if player.Character then
if player.Character.HumanoidRootPart then
local predictedCFrame = CFrame.new(position + assemblyLinearVelocity * UPDATE_RATE) * CFrame.Angles(math.rad(orientation.X), math.rad(orientation.Y), math.rad(orientation.Z))
TweenService:Create(player.Character.HumanoidRootPart, TweenInfo.new(UPDATE_RATE, Enum.EasingStyle.Linear), {CFrame = predictedCFrame}):Play()
end
end
end)