How would I come up with a method to remove a clone of player when they leave/get killed?

So I have a clone of player (Named “clone”), and I need so it gets removed if player (Whose appearance the clone took) leaves or gets killed/resets

You could check when a new character of the player spawned with player.CharacterAdded and you can check if he leaves by just doing game.Players.PlayerRemoving or something like that

I suggest naming that clone in the player’s name, something like Player1_Clone.
And then when that player dies/leaves, look for that clone in workspace and destroy it.

you can use the CharacterRemoving event

maybe something like this

game.Players.PlayerAdded:Connect(function(player)
	local clone = nil

	player.CharacterAdded:Connect(function(character)
		clone = character:Clone()
	end)

	player.CharacterRemoving:Connect(function (character)
		clone:Destroy()
	end)
end)
1 Like
local Game = game
local Workspace = workspace
local Players = Game:GetService("Players")

local Clones = {} --Cache of clones.

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
		Character.Archivable = true
		local Clone = Character:Clone()
		Clones[Player] = Clone
		Character.Archivable = false
		Clone:PivotTo(CFrame.new(0, 0, 0))
		Clone.Parent = Workspace
	end
	
	local function OnCharacterRemoving(Character)
		if Clones[Player] then Clones[Player]:Destroy() end
	end
	
	Player.CharacterAdded:Connect(OnCharacterAdded)
	Player.CharacterRemoving:Connect(OnCharacterRemoving)
end

local function OnPlayerRemoving(Player)
	if Clones[Player] then Clones[Player]:Destroy() end
	Clones[Player] = nil
end

Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
2 Likes