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)?