Rewriting Character Problem

Main Character changing script is written in module and run by serverscript located in server script service

part of module:

local plrChar = plr.Character
char.PrimaryPart = char.HumanoidRootPart
char:SetPrimaryPartCFrame(plrChar.PrimaryPart.CFrame)
char.Name = plr.Name
if plrChar:FindFirstChild("Animate") and not char:FindFirstChild("Animate") then
	plrChar.Animate:Clone().Parent = char
end
if plrChar:FindFirstChild("Health") and not char:FindFirstChild("Health") then
	plrChar.Health:Clone().Parent = char
end
plr.Character = char
local rootPart = char:FindFirstChild("HumanoidRootPart")
local plrRoot = plr.Character:FindFirstChild("HumanoidRootPart")
	if rootPart and plrRoot then
		rootPart.CFrame = plrRoot.CFrame
	end
	for i, part in pairs(char:GetDescendants()) do
	if part:IsA("BasePart") then
		part.Anchored = false
	end
end

the problem i am experiencing is that player is not attatched correctly with new character nor disappearing name of character for client
image
(blue = player cam position, red = character)

Ive tried configuring camera by local script

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = script.Parent:WaitForChild("Humanoid")

but this only fixed camera tracking to player

Summary

  • problem that character name shows even on player
  • new loaded character have really slow delay on animation with movements
  • way to optimize

extra points

  • character is loaded with insert service ( im considering this as problem but i need to keep it )
local IS = game:GetService("InsertService")

local Model = IS:LoadAsset(characterID)
Model.Parent = workspace
for _, Child in pairs(Model:GetChildren()) do
	Child.Parent = Model.Parent
	char = Child
end
Model:Destroy()
4 Likes

what are you specifically trying to do here? switch characters?

3 Likes

yes i am trying to change character by loading character into game with insertservice and change

2 Likes

if you want to apply clothing accessories and such from other characters. use HumanoidDescription.

no it needs to have custom bodyparts

1 Like

Extra note:

  1. player.Character seem perfectly changed
  2. camera is changedinto new character humanoid perfectly
  3. im finding anything i missed

is the humanoidrootpart connected with the torso through a joint?

why dont you just clone the player into a storage (server or replicated, dont matter) and retrieve it and set it to that

1 Like

by the way, are you cloning your character into another character. or from another character into your character.

1 Like

sure it is

Usually roblox doesn’t let us rewrite the .Character property of the player, or well, it just doesn’t work as it should.

If you want to replace your character with another model, what you probably will have to do, instead of just rewriting the .Character property of the player to the new model, replace the parts of the current character with the new character.

In small words, delete all the parts in the current character, then clone all the parts of the character model you want to change to, and parent them back into the player’s character.

Also remember to use BasePart:SetNetworkOwner() on the RootPart of the new character.

I don’t know if what I said makes sense, but that’s how I used to change character models before.

1 Like

i am trying to change player character into specific character model

ok i will try it and tell you what it does

1 Like

or… you could just clone the rig into starterplayer and name it ‘StarterCharacter’
and use this to set new char

local player = game.Players.LocalPlayer

function setChar(char)
   local character = player.Character
   local cf = character.HumanoidRootPart.CFrame
   char.Archivable = true
   local newChar = char:Clone()
   newChar.Parent = game.StarterPlayer
   newChar.Name = "StarterCharacter"
   player:LoadCharacter()
   newchar:Destroy()
   newchar = nil
   player.Character.HumanoidRootPart.CFrame = cf
   player.Character.HumanoidRootPart:SetNetworkOwner(player)
   player.Character.Humanoid.DisplayDistanceType = "None"
   character:Destroy()
   character = nil
end

--setchar(pathtocustomchar)

i think it might get messed with other player character

then you can make it clientsided, lemme edit it

Optimisation: Make sure the character is already unanchored, but keep the root part anchored only.
Then you just need to do this:
char.PrimaryPart.Anchored = false

I have a character-switching script somewhere, i’ll try find it and see why the nametag is appearing for you.

Sorry, I didn’t realise my scripts also make you see your own name.

To fix this, you need a LocalScript which runs the following code on the client:

player.Character.Humanoid.DisplayDistanceType = 'None'

You may wish to use a RemoteEvent to trigger the code on the client, or clone a LocalScript with this code into the new character.

Or add the following code to a LocalScript in ReplicatedFirst or StarterPlayerScripts:

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
  char.Humanoid.DisplayDistanceType = 'None'
end)

Tried the method deleting all things except humanoid inside default character and putting custom character
image
resulted unable to control even jumping and leg is clipping into floor just like platformstand (not enabled)

Module Script:

local plrChar = plr.Character
char.PrimaryPart = char.HumanoidRootPart
char:SetPrimaryPartCFrame(plrChar.PrimaryPart.CFrame)
if plrChar:FindFirstChild("Animate") and not char:FindFirstChild("Animate") then
	plrChar.Animate:Clone().Parent = char
end
if plrChar:FindFirstChild("Health") and not char:FindFirstChild("Health") then
	plrChar.Health:Clone().Parent = char
end

local rootPart = char:FindFirstChild("HumanoidRootPart")
local plrRoot = plr.Character:FindFirstChild("HumanoidRootPart")
if rootPart and plrRoot then
	rootPart.CFrame = plrRoot.CFrame
end

for _, Child in pairs(plrChar:GetChildren()) do
	if not Child:IsA("Humanoid") then
		Child:Destroy()
	end
end
plrChar.PrimaryPart = char.HumanoidRootPart
char:FindFirstChild("Humanoid"):Destroy()
for _, Child in pairs(char:GetChildren()) do
	Child.Parent = plrChar
	char = Child
end
char:Destroy()

for i, part in pairs(plrChar:GetDescendants()) do
	if part:IsA("BasePart") then
		part:SetNetworkOwner(plr)
	end
end
1 Like

i found no error received and properties are perfectly setted