Custom character switches back to Starter Character

  1. What do you want to achieve?
    I have a custom character script that changes the players character by using
plr.Character = model

But when the player dies it switches back to the StarterCharacter
Is it possible for the player to keep the character it switched into?

  1. What is the issue?
    Here is the code for the character switching
local function respawnPlayer(plr, modelName, savelocal)
	local model = game.Workspace:FindFirstChild(modelName)
	local oldModel = plr.Character
	local newModel = model:Clone()
	newModel.Name = plr.Name
	plr.Character = newModel
	newModel.Parent = game.Workspace 
	for _, object in ipairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do 
		local newObject = object:Clone()
		newObject.Parent = game.Workspace:FindFirstChild(plr.Name)
	end
	newModel:SetPrimaryPartCFrame(game.Workspace.SpawnLocation.CFrame)
	oldModel:Destroy()
	game.Workspace:WaitForChild(plr.Name).Humanoid:UnequipTools()
	if not savelocal then
		return			
	end
	savedata(plr, savelocal)
end
  1. What solutions have you tried so far?
    I have searched though multiple forums(including this one) and found nothing
    I have also tried using CharacterRemoving but it detects when the player switches charcters and when the player dies

swaps the humanoid of the model with that of the player character

So instead of using plr.Character = model
I just clone the model and switch the Humanoids?

The respawnPlayer function itself looks fine, so you must not be calling it correctly?

Well I call it correctly, its that since the starter character didn’t change. When the player dies it switches back to starter character

But did you call the function again after the character respawns?

or when humanoid dies (after waiting for it to respawn, or if needed, then using :LoadCharacter() )

I can’t use character removing though how do I detect when the player dies?

By using Humanoid.Died:Connect(function() end)

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