How can I get a players appearance from UserId onto an NPC

I want to spawn an NPC with a players appearance but I keep getting this error;

Unable to cast token to token  -  Server - getCharacterAppearance:9

I am using a module script, so I have to require the module.

Here is my script for the module;

local getCharacterAppearance = {}

function getCharacterAppearance.copy(player:Player)
	local npc = game.ReplicatedStorage:FindFirstChild("ThePlayer"):Clone()
	
	local npcHum = npc:FindFirstChildOfClass("Humanoid")
	local playerHumDesc = game.Players:GetHumanoidDescriptionFromUserId(player.UserId)

	npcHum:ApplyDescription(playerHumDesc, Enum.HumanoidRigType.R6)
	
	local npcHead = npc.Head
	local npcName = npcHead.Overhead
	
	npcName.Username.Text = player.Name
	
	return npc
end

return getCharacterAppearance

The way I am requiring it does not seem to have any issues, if anyone sees an issue within my code please let me know.

2 Likes

ApplyDescription doesnt have a RigType argument

3 Likes

Oh really? So I should try it without?

1 Like

I don’t know where I got that idea from.

1 Like

Well, it seems I have a new error

Humanoid::ApplyDescription() DataModel was not available  -  Server - getCharacterAppearance:9

What could this mean?

1 Like

Do you parent the NPC model to the workspace?

1 Like

Yes, but I already cover that after the script is required

This is a function from my other module;

function doorModule.youarenotyou(player, char, root)
	local npc = getCharacterAppearance.copy(player)
	npc.Parent = game.Workspace.NPCS
	npc.Humanoid:MoveTo(Vector3.new(-1.029, 3, -199.5))
	npc.Humanoid.MoveToFinished:Wait()
	Chat:Chat(npc.Head, "you are not you")
end

I suggest parenting the NPC to workspace in the getCharacterAppearance model.

1 Like

I accidentally made this a solution, but you mean parent it to the workspace before getting the appearance?

Yes, Parent it to workspace in the same function.

1 Like

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