Making the NPC Looks like the local player

I’m making a meme game with some friends. I’m trying to make the person on the train track look like the person who is in the game. I used load character plugin to load the npc into the game.


Here is the script I tried using:

local playerService = game:GetService("Players")

playerService.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local humanoid = Character:WaitForChild("Humanoid")
		local humanoidDescription = humanoid:GetAppliedDescription()
		local npcHumanoid = game.Workpace.e.Humanoid
		npcHumanoid:ApplyDescription(humanoidDescription)
	end)
end)

I tried looking on the dev forum for any articles related to this. Please point me in the right direction, thanks.

3 Likes

Are you getting errors? There’s at least one typo in your code:

game.Workpace.e.Humanoid

Also, do you intend this to constantly change the character on the tracks to the most-recently-respawned player? Because that’s what this code looks like its doing,

Yea this code is obviously on the server even though you want it local.

1 Like

It’s a one player server, so I assumed that would work. How would I make it local?

game.Players.LocalPlayer.CharacterAdded:Connect(function(Character)
	local humanoid = Character:WaitForChild("Humanoid")
	local humanoidDescription = humanoid:GetAppliedDescription()
	local npcHumanoid = workspace.e.Humanoid
	npcHumanoid:ApplyDescription(humanoidDescription)
end)

You would probably also want to run that code once when the player initially joins, in case their character already exists by the time the CharacterAdded event is hooked up.

1 Like

Thanks, where should I put the script? In ServerScriptService?

Try this:

local appearanceModel = game.Players:GetCharacterAppearanceAsync(player.UserId)
appearanceModel.Parent = game.Workspace

Thanks. Where should i put it? In ServerScriptService?

You should put the script in PlayerScripts and your script should be a local script

Thanks. The problem is I’m trying to make it so the npc looks like the player in-game. Do I still need to put it in PlayerScripts?

Yes, the local script will run if your local script is inside a player. PlayerScripts will clone all the scripts and put 'em in the players

Sadly it didn’t work. I used the exact script you told me to use.

game.Players.PlayerAdded:Connect(function(p)

local appearanceModel = game.Players:GetCharacterAppearanceAsync(p.UserId)

appearanceModel.Parent = game.Workspace.e --- e is the model name.

Is there any error?
(30charss)


Yes, here is one error I encountered.

Maybe you forgot an ‘end’
(30 chars)


It causes the end to be an error.

Run the script,then tell me the error in the output or just check for any error message in the script

I tried it and it didn’t work. I assume it’s because you only used a variable and didn’t actually run anything. I might be wrong though.

If that method doesn’t work, I’m sure that my alternative one will function as intended, but I’d wait for the character to load in, anchor the parts, clone yourself and position every single character part to the same position (this also goes with Orientation). For your scenario:

local npc = game.Workspace:FindFirstChild("YOUR_NPC_NAME")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
repeat wait()
	char.Archivable = true
	local clone = char:Clone()
	for _, i in pairs(clone:GetDescendants()) do
		if i:IsA("MeshPart") then
			i.Anchored = true
			i.Position = npc:FindFirstChild(i.Name).Position
			i.Orientation = npc:FindFirstChild(i.Name).Orientation
		end
		if i:IsA("Part") then
			i.Anchored = true
			i.Position = npc:FindFirstChild(i.Name).Position
			i.Orientation = npc:FindFirstChild(i.Name).Orientation
		end
	end
	char.Archivable = false
	clone.Parent = npc
until game:IsLoaded()
-- localscript in StarterPack
1 Like

Sadly that didn’t work. Any idea why?