Make NPC's Name with player's name

Hello Everyone!

I want to make NPC’s Name with player’s name → different for every player, should I use localScript or Script? And where should I put it?
But I can’t get the name of the NPC I try to get the name with this:

local LocalNPC = game.Workspace:findFirstChild(player.Name)

game.Players.PlayerAdded:Connect(function(player)
	LocalNPC:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(player.UserId))
	game.Workspace.Dummy2.Name = player.Name
end)`

:point_up_2: The script located in workspace with a normal script, not localscript
Thanks! Hopefully someone know how to fix this :D.

Put this in your plrAdded function.

local desc = game.Players:GetHumanoidDescriptionFromUserId(player.UserId) workspace.Dummy2.Humanoid:ApplyDescription(desc) workspace.Dummy2.Name = playerName

This code gets your player’s HumanoidDescription and applies it to “Dummy2”

Edit: Line 1 will not work, it needs to be under the event (unless you have code that I can’t see.)

1 Like

You should use a LocalScript
Put this in a localscript:

workspace:WaitForChild("Dummy2").Name = game.Players.LocalPlayer.Name

Don’t have to do anything on the server!

1 Like

So, does my script already correct? the only thing I need to do is put it in a localscript right?

Nope, you don’t have to connect to PlayerAdded, since it’s in a localscript

Will try this, Thank you so much!

I didn’t see that you wanted to change the character to the player’s character locally, here:

local dummy = workspace:WaitForChild("Dummy2")
dummy.Name = game.Players.LocalPlayer.Name
dummy:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players.LocalPlayer.UserId))
1 Like

image
Nope

Sorry, I updated my script, did you use my updated script? Also, can you check the output for any potential errors?

1 Like

One more thing, this is for a story game, so I have the main script which is a script, not local script. And I also use the dummy2 in the script, how do I change this?
For example:
local controller = game.Workspace.Dummy2.Humanoid
setDialogueImageEvent:FireAllClients(game.Workspace.Dummy2, Color3.new(0.627451, 1, 0.815686))

Yup, I use your updated script, put it in workspace and it is a localscript

You don’t have to change this! The name change is only done on the client, so you only need to do something if you’re accessing the Dummy from the client.

1 Like

Put the LocalScript under StarterPlayerScripts or StarterGui

image
image

1 Like

Ah, got it, lemme try to put it in starterplayerscript

Incredible, the name got change, but the avatar didnt change to player’s avatar

Ohh! Sorry I called ApplyDescription on the rig, not the humanoid!
try this

local dummy = workspace:WaitForChild("Dummy2")
dummy.Name = game.Players.LocalPlayer.Name
dummy.Humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players.LocalPlayer.UserId))
1 Like


HMMMM weird, I only put 1 “:” but it shows Humanoid::ApplyDescription()

This is a hacky way to bypass this issue, but here:

local dummy = workspace:WaitForChild("Dummy2")
dummy.Name = game.Players.LocalPlayer.Name
local humanoid = dummy.Humanoid:Clone()
dummy.Humanoid:Destroy()
humanoid.Parent = dummy
humanoid:ApplyDescription(game.Players:GetHumanoidDescriptionFromUserId(game.Players.LocalPlayer.UserId))

Unfortunately the Build Rig plugin isn’t working for me at the moment so I can’t test it

Basically, the Humanoid of the Rig belongs to the server, if we

make a copy of the humanoid (now that copy belongs to the client)
and
destroy the humanoid (the one that belongs to the server)

:ApplyDescription will work

1 Like

Yup, its working, Thank you so much for your help!

miscellaneous Problem:
So I just realise I have this local script too that I used to play animation. maybe you ask why I put it in the local script? Because I already try it when I put it in the script, the animation not loading because of laggy

so this is the script of the animation script

local controller = game.Workspace.Dummy2.Humanoid

local AnimCall = Instance.new("Animation")
AnimCall.AnimationId = "http://www.roblox.com/asset/?id=9112553567"
local Call = controller:LoadAnimation(AnimCall)
local PlayerCallAnimationEvent = game.ReplicatedStorage.Remotes.PlayerCallAnimationEvent

PlayerCallAnimationEvent.OnClientEvent:Connect(function()
	Call:Play()
	wait(Call.Length - 0.1)
	Call:AdjustSpeed(0)
end)

1 Like