Efficient way to load custom characters

I’m wanting to load custom characters in, like how naming a model StarterCharacter in StarterPlayer works. Problem with that is you’re locked to a single character model. I want player’s to be able to toggle in different characters.

I tried this but this just results in infinite loading

player.CharacterAdded:Connect(function(character: Model)
	local StarterCharacterModel = Assets.Characters[Data.LastCharacter]:Clone()

	local NewCharacter = StarterCharacterModel:Clone()
	NewCharacter.Name = player.Name

	player.Character = NewCharacter
	player.Character.Parent = workspace
	player.Character:PivotTo(character:GetPivot())

	character:Destroy()
end)

player:LoadCharacter()

This isn’t HumanoidDescriptions either, so I’m not using that

3 Likes

i remember having a similar issue and iirc my solution was to have a variable called “newChar” which was set to false by default but was set to true when the character was made then set back to false after destroying the old character and their was an if statement to check if it was set to false

e.g.

local newChar = false

if newChar == false then
	player:LoadCharacter()
	player.CharacterAdded:Connect(function(character: Model)
		local StarterCharacterModel = Assets.Characters[Data.LastCharacter]:Clone()
	
		local NewCharacter = StarterCharacterModel:Clone()
		NewCharacter.Name = player.Name
	
		player.Character = NewCharacter
		player.Character.Parent = workspace
		player.Character:PivotTo(character:GetPivot())
		newChar = true
		character:Destroy()
		task.wait(0.1)
		newChar = false
	end)
end

which now looking at is just a cooldown

function onCharacterAdded()
	local character : Model = player.Character

	if character:HasTag("Morph") then return end

	local newCharacter = Assets.Characters[Data.LastCharacter]:Clone()

	newCharacter.Name = player.Name
	newCharacter.Parent = workspace
	newCharacter:PivotTo(character:GetPivot())
	newCharacter:AddTag("Morph")

	player.Character = newCharacter
end

onCharacterAdded()
player.CharacterAdded:Connect(onCharacterAdded)

Try doing something like this instead, i quickly wrote this so there might be errors but everytime the player’s character is changed roblox will automaticly clean up the old one so you don’t have to be destroying it manually. I saw that you also seem to be cloning the “StarterCharacterModel” for some reason twice?? Now since roblox fires the CharacterAdded signal everytime the character is updated we are simply adding the “Morph” tag to make sure the function is only called for default characters and if the player already has a morph equipped then we won’t do anything

1 Like

my method is to just swap the body parts but thats because all the models have the same parts just different meshes

My custom character gets stuck in a T-Pose state + camera doesn’t follow the character around. I tried cloning the Animate script into them too, and that didn’t fix either issue

1 Like

You will need a custom animate script for the Characters and for the Camera you can just make a simple LocalScript to update the camera like this:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

function fixCamera()
	local currentCamera = workspace.CurrentCamera
	local playerCharacter = LocalPlayer.Character

	if playerCharacter == nil then return end

	local humanoid : Humanoid = playerCharacter:WaitForChild("Humanoid")

	currentCamera.CameraSubject = humanoid
end

fixCamera()
LocalPlayer:GetPropertyChangedSignal("Character"):Connect(fixCamera)

I already did have a custom animate script.

this didn’t fix it though :confused:

EDIT Nvm was my fault, I was parenting the Animate before setting the character

1 Like

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