StarterCharacterScript bugs out when player dies, Character "disappears"

In my game I am trying to make dead players’ characters stay laying around by cloning their dead characters before they respawn. Problem is when I go to get the character model using script.Parent it returns a nil value. I’m not sure how it is even possible for a script to not have a parent.

The following code executes as a character script whenever the humanoid dies.

	local Character = script.Parent
	local Player = game:GetService("Players"):FindFirstChild(Character.Name)
	wait(game:GetService("Players").RespawnTime)
	local CharClone = script.Parent:Clone()
	CharClone.Name = "Corpse"
	CharClone.Parent = game.Workspace
	Player:LoadCharacter()

Use the “Archivable” property

local Character = script.Parent
local Player = game:GetService("Players"):FindFirstChild(Character.Name)

wait(game:GetService("Players").RespawnTime)

script.Parent.Archivable = True
local CharClone = script.Parent:Clone()
script.Parent.Archivable = False

CharClone.Name = "Corpse"
CharClone.Parent = game.Workspace
Player:LoadCharacter()

There is a post about this here: How would I create a clone of a player in-game?

Had no clue about the Archivable property, thanks.

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