Player's Character Cloning Issues On Client

I made a simple local script that clones the player’s character but it just doesn’t work for some reason.

I have completely no idea what causing this…

I even tried out the code on the server script but it still resulted in the same error message, this really ticked me off.

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")
	
	local camera = game.Workspace.Camera
	
	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)
	
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)
	
	--local function cameraloop ()
	--	camera.CFrame = 
	--end
	
	
	local startingpos = "2.475, -212.676, 312.173"
	

	player.Character.Archivable = true
	local clone = character:Clone()
	clone.Parent = game.Workspace
	player.Character.Archivable = false
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"
	
	clone.PrimaryPart = clone.HumanoidRootPart
	
	clone.HumanoidRootPart.Position = startingpos
	
	
	
end)

3 Likes

Looking at your error message, maybe try using clone.PrimaryPart instead of HumanoidRootPart. You, of course, have to set the HumanoidRootPart to the PrimaryPart of the model if you haven’t yet.

I modified your code and this could work:

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
    print("Client received")

    local camera = game.Workspace.CurrentCamera
    local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)
    
    local player = game.Players.LocalPlayer
    local character = player.Character
    local startingpos = Vector3.new(2.475, -212.676, 312.173)
    
    if not character then
        character = player.CharacterAdded:Wait()
    end

    bom1:UIs(player, 1.5, "Black", 0.5)

    local clone = character:Clone()
    clone.Parent = game.Workspace
    clone:SetPrimaryPartCFrame(CFrame.new(startingpos)) -- Set the position using CFrame
    
    -- Optionally, you can create a force field for the clone
    local immu1 = Instance.new("ForceField", clone)
    immu1.Visible = false
    local immu2 = Instance.new("ForceField", clone)
    immu2.Visible = false
    immu2.Name = "Iframes"

    player.Character = clone
    clone.HumanoidRootPart.CFrame = CFrame.new(startingpos) -- Set the position again

    wait(0.1) -- Wait for the character to load

    camera.CameraType = Enum.CameraType.Custom
    camera.CFrame = CFrame.new(clone.HumanoidRootPart.Position + Vector3.new(0, 5, -10), clone.HumanoidRootPart.Position)

    -- Restore the original character after some time
    wait(5) -- Adjust the time as needed
    player.Character = character
    clone:Destroy()
end)

In this modified code:

  1. I’ve made sure that the character variable is set correctly
  2. I’ve used Vector3.new for the startingpos variable
  3. I’ve used the SetPrimaryPartCFrame method to set the position of the clone
  4. I’ve set the camera.CameraType and camera.CFrame to focus on the clone
  5. After a certain time (you can adjust the waiting time), it restores the original character and destroys the clone

Hope this helps!

1 Like

I used ur code and it didn’t work, this is just odd and weird.
Such simple lines of code and it wouldn’t work, they all look right and should work.

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")

	local camera = game.Workspace.Camera

	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)

	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)

	--local function cameraloop ()
	--	camera.CFrame = 
	--end


	local startingpos = "2.475, -212.676, 312.173"


	player.Character.Archivable = true
	local clone = character:Clone()
	clone.Parent = game.Workspace
	player.Character.Archivable = false
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"

	clone.PrimaryPart = clone.HumanoidRootPart

	clone.PrimaryPart.Position = startingpos



end)

I set the primary part to head and also referred HumanoidRootPart as Character.PrimaryPart but still doesn’t work.

Make sure to change the Archivable property of the character to the opposite of what it currently is.

I changed the Archivable property to true but the StarterCharacter I have is already set to true, so if I’m following what you said I change the Archivable property to the opposite of the StarterCharacter which is going to be false.

By doing this wouldn’t it make cloning the character impossible?

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")

	local camera = game.Workspace.Camera

	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)

	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)

	--local function cameraloop ()
	--	camera.CFrame = 
	--end


	local startingpos = "2.475, -212.676, 312.173"


	player.Character.Archivable = false
	local clone = character:Clone()
	clone.Parent = game.Workspace
	player.Character.Archivable = true
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"

	clone.PrimaryPart = clone.HumanoidRootPart

	clone.PrimaryPart.Position = startingpos



end)

Still is the same issue occuring

But lets say I completely remove and stop changing and set the Archivable property,

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")

	local camera = game.Workspace.Camera

	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)

	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)

	--local function cameraloop ()
	--	camera.CFrame = 
	--end


	local startingpos = "2.475, -212.676, 312.173"


	--player.Character.Archivable = false
	local clone = character:Clone()
	clone.Parent = game.Workspace
	--player.Character.Archivable = true
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"

	clone.PrimaryPart = clone.HumanoidRootPart

	clone.PrimaryPart.Position = startingpos



end)

The same issue somehow still occurs…

the cloned can’t be parented?

But the code itself, everything is right and should work like it should.

I have no idea :skull:

My mind is blank

1 Like
game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")

	local camera = game.Workspace.Camera

	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)

	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)

	--local function cameraloop ()
	--	camera.CFrame = 
	--end


	local startingpos = "2.475, -212.676, 312.173"


	--player.Character.Archivable = false
	local clone = character:Clone()
	clone.Parent = game.Workspace
	--player.Character.Archivable = true
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"

	clone.PrimaryPart = clone:WaitForChild("HumanoidRootPart")

	clone.PrimaryPart.Position = startingpos



end)
clone.PrimaryPart = clone:WaitForChild("HumanoidRootPart")

I changed it to that but the problem still continues to occur

game.ReplicatedStorage.StorylineRemotes.Chapter1.Remote1.OnClientEvent:Connect(function()
	print("Client received")
	
	local camera = game.Workspace.Camera
	
	local bom1 = require(game.ReplicatedStorage.UIModules.BOrWModule)
	
	local player = game.Players.LocalPlayer
	local character = player.Character or player.CharacterAdded:Wait()
	bom1:UIs(player,1.5,"Black",0.5)
	
	--local function cameraloop ()
	--	camera.CFrame = 
	--end
	
	
	local startingpos = "2.475, -212.676, 312.173"
	

	player.Character.Archivable = true
	local clone = character:Clone()
	clone.Parent = game.Workspace
	player.Character.Archivable = false
	local immu1 = Instance.new("ForceField",clone)
	immu1.Visible = false
	local immu2 = Instance.new("ForceField",clone)
	immu2.Visible = false
	immu2.Name = "Iframes"
	
	clone.PrimaryPart = clone.HumanoidRootPart
	
	clone.HumanoidRootPart.Position = startingpos
	
	
	
end)

Thats exactly what I did, look at the top messages.

I always had Archivable set to true before cloning player’s character