Hitbox in server and visual in client sync problem

Hello there i’m having this tiny problem where the hitboxes lag behind

The red part is the part that is being positioned by the server
The white one is being handled by the client so it’s not lagging behind only the server one any help?

What should i do to sync it?

Server Script

function playerJoined(player: Player)
	print("is this working")
	player.CharacterAdded:Connect(function(character)
		print("is this working")
		local clone = helicopter:Clone()
		local hitbox = raycastHitbox.new(clone)
		local tempFilter = {}
		hitbox.Visualizer = true
		hitbox.DetectionMode = 1
		hitbox:HitStart()
		hitbox.OnHit:Connect(function(hit)
			print(hit)
			if hit:IsA("Part") or hit:IsA("MeshPart") then
				if hit.Parent.Parent.Name == "Enemy" and hit.Parent.Parent:IsA("Folder") then
					local char = hit.Parent
					local humanoid = char:FindFirstChild("Humanoid")
					if humanoid then
						table.insert(tempFilter, char)
						RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
						hitbox.RaycastParams = RaycastParamss
						hitbox:HitStop()
						hitbox:HitStart()
						humanoid:TakeDamage(10)
						task.wait(.3)
						for i,v in ipairs(tempFilter) do
							if char == v then
								table.remove(tempFilter,i)
								RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
								hitbox.RaycastParams = RaycastParamss
								return
							end
						end
					end
				end
			end
		end)
		clone.Parent = workspace
		clone.Transparency = 0
		local humanoid = character:WaitForChild("HumanoidRootPart")
		clone.CFrame = humanoid.CFrame
		RunService.Heartbeat:Connect(function()
			local ping = player:GetNetworkPing()
			if ping ~= 0 then
				clone.CFrame = CFrame.new(humanoid.Position * ping) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
			else
				clone.CFrame = CFrame.new(humanoid.Position) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
			end
		end)
		character.Humanoid.Died:Connect(function()
			task.wait(3)
			player:LoadCharacter()
		end)
	end)
	player:LoadCharacter()
end

Local Script

local RunService = game:GetService("RunService")
local repStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RotationSpeed = 4
local character = script.Parent

local helicopter = repStorage:WaitForChild("Helicopter")
local clone = helicopter:Clone()
clone.Parent = character
local humanoid = character:WaitForChild("HumanoidRootPart")
clone.CFrame = humanoid.CFrame
RunService.Heartbeat:Connect(function()
	clone.CFrame = CFrame.new(humanoid.Position) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
end)

For more info
i’m using heartbeat service to position the part in the server and also in the client

Weld the part to the character instead of updating the position

I actually have done this however i’m experiencing a problem where if i rotate my character opposite the part where it is rotating to it just stops.


I’m using weld for this and rotating the c0

function playerJoined(player: Player)
    print("is this working")
    player.CharacterAdded:Connect(function(character)
        print("is this working")
        local clone = helicopter:Clone()
        clone.Parent = character
        local humanoid = character:WaitForChild("HumanoidRootPart")
        clone.CFrame = humanoid.CFrame
        local motor = Instance.new("Weld")
        motor.Parent = clone
        motor.Part0 = humanoid
        motor.Part1 = clone
        RunService.Heartbeat:Connect(function()
            motor.C0 = motor.C0 * CFrame.Angles(0, math.rad(RotationSpeed), 0)
        end)
        character.Humanoid.Died:Connect(function()
            task.wait(3)
            player:LoadCharacter()
        end)
    end)
    player:LoadCharacter()
end

This is the code

Are you sure you’re not just in sync with the part?

I’m sure that the hitbox is not in sync as shown in the video, i could use a weld but the problem is it would get stuck whenever i rotate my character too.

Have you tried using a motor to constantly rotate the part instead of having to update it?

The only way to sync this is to have 0 ms of ping. What you’ve coded is essentially a visualization of client to server communication lag. The client will never send a message that the server receives instantly.