Heartbeat offsetting visibly lagging behind

  1. What do you want to achieve? I want to make it not lag behind

  2. What is the issue? The subject is lagging behind https://www.youtube.com/watch?v=fM5ObUDzd4o

I asked how I would fix this over at the Scripting Helpers Discord and someone told me that I should set the officer’s network owner to the client and have the client do it on renderstep.

What would be the best way to do the server-client communication?

I’m currently using Heartbeat on the server as you can see below

Handcuffs Grab Method

function Handcuffs:Grab(Subject)
    if not Subject:IsA("Player") then return end

    self.Officer = self._EquipTrack.Player.Value
    self.Subject = Subject
    --TODO: Disable Backpack and Unequip currently equipped tool of Subject

    FastSpawn(function()
	    HumanoidUtil.ForceUnseatHumanoid(Subject.Character.Humanoid)
	    CharacterUtil.GetPlayerRootPart(self.Subject).Anchored = true
	    self.Grabbing = true
        --Heartbeat--
	    self._Heartbeat = RunService.Heartbeat:Connect(function()
		    CharacterUtil.GetPlayerRootPart(self.Subject).CFrame = CharacterUtil.GetPlayerRootPart(self.Officer).CFrame * CFrame.new(Vector3.new(2.5,0,-5))
	    end)
    end)
end

I’d say don’t use Heartbeat, instead use RenderStepped as it’s a lot faster.

I don’t know what the best way to do the server-client communication is

You can fire two events : Handcuff and ReleaseHandcuff
Handcuff will bind the subject in a bindtorenderstep and ReleaseHandcuff will remove that bind. (on server)

1 Like

I have this now in StarterCharacterScripts but I’m not sure how to pass in the Subject to OffsetSubject

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")

function OffsetSubject()

end

Remotes.HandcuffGrab.OnClientEvent:Connect(function()
    RunService:BindToRenderStep("offsetBinding", 100, OffsetSubject)
end)

Remotes.HandcuffRelease.OnClientEvent:Connect(function()
    RunService:UnbindFromRenderStep("offsetBinding")
end)

Change

RunService:BindToRenderStep('name',100,func)
--to
RunService:BindToRenderStep('name',Enum.RenderPriority.Camera.Value + 1,func)
1 Like