Jittering Action of player Clone

I am trying to create a system where a player can clone themselves, and that clone follows the player around copies their exact movement.

I am currently doing this all on the server side, here is the function that handles this logic:

function Shared.ClonePlayer(player: Player)
	local character = player.Character
	if not character then return end
	
	local playerRoot = character:FindFirstChild("HumanoidRootPart")
	local playerHumanoid = character:FindFirstChildOfClass("Humanoid")
	if not playerRoot or not playerHumanoid then return end
	
	character.Archivable = true
	local characterClone = character:Clone()
	characterClone.Parent = Workspace
	character.Archivable = false
	
	local cloneHumanoid = characterClone:FindFirstChildOfClass("Humanoid")
	local cloneRoot = characterClone:FindFirstChild("HumanoidRootPart")
	if not cloneHumanoid or not cloneRoot then return end
	
	for _, part in pairs(characterClone:GetChildren()) do
		if part:IsA("BasePart") then
			part.Anchored = true
		end
	end
	
	local moveOffset = CFrame.new(0, 0, 3) 

	
	RunService.Heartbeat:Connect(function()
		for _,child:Instance in pairs(character:GetChildren()) do
			if child:IsA("BasePart") and child.Name ~= "HumanoidRootPart" then
				characterClone:FindFirstChild(child.Name).CFrame = characterClone:GetPivot():ToWorldSpace(character:GetPivot():ToObjectSpace(child.CFrame))

			end
		end
		
		characterClone:PivotTo(character:GetPivot() * moveOffset)

	end)
end

However, as seen in this video:


It is very laggy and glitchy in studio.
Does anyone have any idea on how to stop this? (Maybe some other logic)?

1 Like

Try setting the ownership of the clone to the client, or do this effect entirely on the client.

My clone is anchored, I get the error: "Network Ownership API cannot be called on Anchored parts or parts welded to Anchored parts. "

Since it’s anchored, the network cannot take ownership of the model. This will have to be done on the client if you want smoothness; the roughness is due to latency between the client and server.

Is there a way to copy the movement with the parts unanchored?

Yes, but I would say that this would be done much easier entirely on the client. Again, the latency between the client and server is the cause of the jitter, so you can either a) find a way to replicate the movement while leaving the parts unanchored or b) keep the parts anchored and do it on the client.

Both approaches have pros/cons, but the second approach is the easiest imo.

How would I implement the second option. Would I clone on the server, and use a remote event to pass the position of the player to the clone?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.