How to change an NPC to the local player's avatar?

Hey. So I am trying to make a dummy in my game become the player’s avatar. Though there is a problem. It changes the dummy to the NEWEST player added. For example, I join the game and it becomes my avatar, but then someone else joins and it becomes their avatar. I am trying to make it so it only becomes the local player’s avatar, without it changing to someone else’s. I will explain more if I am not clear enough on what I am trying to do.

If anyone trys to help me, I want them to modify this script:

local Players = game:GetService("Players");

local Dummy = workspace.Morphs.AvatarMorph
local DummyHumanoid = Dummy.Humanoid

Players.PlayerAdded:Connect(function(plr)
	local humDes = Players:GetHumanoidDescriptionFromUserId(plr.UserId);
	if(humDes)then
		DummyHumanoid:ApplyDescription(humDes);
	end
end)

local Players = game:GetService("Players");

local Dummy = workspace.Lobby.AvatarMorph
local DummyHumanoid = Dummy.Humanoid

Players.PlayerAdded:Connect(function(plr)
	local humDes = Players:GetHumanoidDescriptionFromUserId(plr.UserId);
	if(humDes)then
		DummyHumanoid:ApplyDescription(humDes);
	end
end)
1 Like

I’m not sure if I understood it. You want every player to see the same NPC as their character?

You’re running this in the server and using PlayerAdded, which will fire every time any player is added. To make the NPC look like the local player, make a local script in StarterCharacterScripts. Try something like this:

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

local Dummy = workspace.Morphs.AvatarMorph
local DummyHumanoid = Dummy.Humanoid

local humDes = Players:GetHumanoidDescriptionFromUserId(localPlayer.UserId);
if(humDes)then
	DummyHumanoid:ApplyDescription(humDes);
end

So I want to make a cutscene with the players avatar in it. And as a place holder I use a dummy in the workspace with the core animations.

I’ll try yours out, this is exactly what I was looking for

I get this error: Humanoid::ApplyDescription() can only be called by the backend server
(Line 10)

Sorry, I didn’t realize that doesn’t work on client. This script will create a new model that looks like the player, you just need to put a part named Placeholder at the dummy’s position and get rid of the dummy.

local Players= game:GetService("Players")
local placeholder = workspace.Morphs.AvatarMorphs.Placeholder

local function cloneCharacter(playerID, playerName)
	local clonePlayer = Players:CreateHumanoidModelFromUserId(playerID)
	clonePlayer.Name = playerName
	
	clonePlayer.PrimaryPart.Position = placeholder.Position
	clonePlayer.PrimaryPart.Anchored = true
	clonePlayer.Name = "Dummy"
	clonePlayer.Parent = workspace
end

local player = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):wait()
cloneCharacter(player.userId, player.Name)

Got it, I’ll give it a try now

Do I put the script in workspace or starter character?

It should be a local script in starter character.
Anything that you want to appear separately for every client should be in a LocalScript, and the only places where LocalScripts run are the Player’s Backpack, StarterCharacterScripts (or in the StarterCharacter), StarterPlayerScripts, PlayerGui, and ReplicatedFirst.

Alright it spawned the avatar give me one sec and let me test it

Did the script call the placeholder dummy, “Dummy” ?

Yes. You can change this line if you want it to be different:

clonePlayer.Name = "Dummy"

And now that I think about it, you may want it to be in the original folder, so put this line in:

clonePlayer.Parent = placeholder.Parent

instead of this one:

clonePlayer.Parent = workspace

I am also trying to make a morph out of the player, but whenever I use the proximity prompt, nothing happens

I used a “Wait for child” line of code for the Dummy if you were wondering

Oh wait the dummy is in workspace that’s why

It would wait for it to spawn in the folder, but it wouldn’t

Yeah just do this and it should be fixed.

Did the script anchor the dummy?

Yes. If that’s a problem, just delete this line or set it to false.