Is there any way to make a copy of the player's body?

Hello! I would like to know how I can make a copy of the players for when they die, I did it this code but it tells me that the starterplayer cannot be copied, how can I solve it, is there any other way?

--Make clones

local char = game.StarterPlayer.StarterCharacterScripts

local cplayer = game.Players:GetPlayerFromCharacter(char)

-- Get services

local Players = game:GetService("Players")

local function PlayerDie()

print("you are dead now..")

end

-- Player spawn

local function OnPlayerSpawn(character)

print("you just spawn.")

local Humanoid = character:WaitForChild("Humanoid")

Humanoid.Died:Connect(PlayerDie)

char.Archivable = true

local clonechar = char:Clone()

clonechar.Name = cplayer.Name.."'s Body is here..."

end

-- Player Added to the game

Players.PlayerAdded:Connect(function(player)

print(player.Name .. " joined the game!")

player.CharacterAdded:Connect(OnPlayerSpawn) --:Connect() is used for hooking functions to events so when event fires, functions attached to the event gets called.

end)

-- When the player left

Players.PlayerRemoving:Connect(function(player)

print(player.Name .. " left the game!")

end)

So I’m going to make a couple of assumptions here;

  1. This is a local script. If that’s the case, it’s immediately an issue. When a local script on a players client interacts with the server (think: the world or anything in it), it’s not replicated across other clients. This means that other players will not be able to see those changes!

  2. You’re trying to get the character from StarterCharacterScripts. The character can actually be accessed from the player itself, as its a property of each player. If you want this to work, you’d need to make a server sided script that does the following:

     local players = game:GetService("Players") --Assign the players service to a variable
    
     players.PlayerAdded:connect(function(player) --When a player joins the game...
     	player.CharacterAdded:connect(function(character) --When that players character spawns...
     		local humanoid = character:WaitForChild("Humanoid") --Wait for the humanoid
     		humanoid.Died:connect(function() --When the humanoid dies...
     		local clone = character:Clone() --Clone the character
     		clone.Parent = Workspace --Add the clone to the workspace
     		end)
     	end)
     end)
    
1 Like

So, first off I suggest transferring this to a Server Script. The code would then be this:

local Players = game:GetService("Players")

Players.PlayerAdded.Connect(function(player)

--Make clones

local char = player.Character

local function PlayerDie()

print("you are dead now..")

end

-- Player spawn

local function OnPlayerSpawn(character)

print("you just spawn.")

local Humanoid = character:WaitForChild("Humanoid")

Humanoid.Died:Connect(PlayerDie)

char.Archivable = true

local clonechar = char:Clone()

clonechar.Name = cplayer.Name.."'s Body is here..."

end

-- Player Added to the game

Players.PlayerAdded:Connect(function(player)

print(player.Name .. " joined the game!")

player.CharacterAdded:Connect(OnPlayerSpawn) 

end)

-- When the player left

Players.PlayerRemoving:Connect(function(player)

print(player.Name .. " left the game!")

  end)
end)
2 Likes