How to load a players outfit onto an NPC locally?

Hello! I’m trying to get a script I found on the Dev Forums to run locally so a player can see their own outfit and another player can see theirs, all on one NPC. This script is in Server Script Service, and it is just a normal script.

local players = game:GetService("Players")

local npc = workspace.Dummy
local npcHuman = npc.Humanoid

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end

		local human = character:WaitForChild("Humanoid")
		local description = human:GetAppliedDescription()
		npcHuman:ApplyDescription(description)
	end)
end)
2 Likes

Remove the playerAdded event, and declare player as players.LocalPlayer at the top anywhere below players. Should work.

1 Like

This shows an error

local player = game.Players.LocalPlayer

local npc = workspace.Dummy
local npcHuman = npc.Humanoid

	player.CharacterAdded:Connect(function(character)
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end

		local human = character:WaitForChild("Humanoid")
		local description = human:GetAppliedDescription()
		npcHuman:ApplyDescription(description)
	end)

On line 7, it says that: ServerScriptService.AnimPlay:7: attempt to index nil with ‘CharacterAdded’

Also, do I have to make this script a local script?

By locally I’m assuming the local client would be the only one being able to see this (sorry in advance if I’m wrong). This is very simple, you would just need to put the clothes in PlayerGui, so only the player can see their outfit on the NPC. I would put the script on the NPC because it is just easier to find it there.

How would I put the clothes in the Player Gui? I had also tried putting the script inside the NPC, although to no avail.

You just set the parent to playerGui. Heres an example:

local clothes = game.Workspace.cloth
local players = game:GetService("Players")

local npc = workspace.Dummy
local npcHuman = npc.Humanoid

players.PlayerAdded:Connect(function(plr)
	local plrGui = plr.PlayerGui
        clothes.Parent = plrGui
end)

If it is that difficult, I would recommend placing it back. You can put it in the NPC if you want, but you need to change everything. Example:

--BEFORE THE CHANGE
local hat = game.Workspace.hat
print(hat.Name" is very small")

--AFTER THE CHANGE
local hat = script.Parent
print(hat.Name" is very small")

I don’t really know if I’d want to change everything, although the original script in the first post works, its just, for example.

If a player, I’ll call “Player 1” if Player 1 joins, their outfit is loaded right onto the character, although for when another player “Player 2” joins, their outfit is loaded onto the NPC, wiping the original outfit of Player 1, and replacing with the outfit of Player 2. I just want to make it so that when a player joins, its only their outfit, and it doesn’t change when another player joins.

Could I see a video? I am very confused sorry :angst:

What I think needs to happen is just put the clothes again under PlayerGui and don’t wipe the clothes. This is because everything under PlayerGui is just for that one player. Example:

Rock not in PlayerGui:

Player1 can see just fine
Player2 can see just fine

Rock in Player1’s PlayerGui:

Player1 can see just fine
Player2 can’t see at all

1 Like


This is what happens when I join the game, although when another player joins, it changes the NPC’s outfit entirely.

1 Like

Ok, I understand now. is the code you showed me before the full code?

1 Like
local players = game:GetService("Players")

local npc = workspace.Dummy
local npcHuman = npc.Humanoid

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end

		local human = character:WaitForChild("Humanoid")
		local description = human:GetAppliedDescription()
		npcHuman:ApplyDescription(description)
	end)
end)

This was the code that I had used that made this happen.

Oh great… Does the clothes have a variable?

I don’t think so, it just detects for when a player joins, waits to get their outfit, gets the player’s outfit description, and loads it onto the NPC.

I have no idea what you did here (sorry) could you put the clothes in a variable?

Sorry, how would I get the player’s accessories as a variable?

I’m guessing this means the outfit info. In this case you would need to put it in PlayerGui by doing something along the lines of this:

local players = game:GetService("Players")

local npc = workspace.Dummy
local npcHuman = npc.Humanoid

players.PlayerAdded:Connect(function(player)
    local playerGui = player.PlayerGui
	player.CharacterAdded:Connect(function(character)
		if not player:HasAppearanceLoaded() then
			player.CharacterAppearanceLoaded:Wait()
		end

		local human = character:WaitForChild("Humanoid")
		local description = human:GetAppliedDescription()
        description.Parent = playerGui
		npcHuman:ApplyDescription(description)
	end)
end)

Hopefully this works :doh:

Unfortunately, for when I had tried this on 2 separate accounts, it hadn’t worked. When I joined the game it had displayed my avatar, although for when the other person joined, it changed it to their avatar, and hadn’t kept the same for my avatar.

Does it have to be put somewhere else other than Server Script Service, or do I have to change it to Local Script?

I think I know the problem: You are still changing the clothes! You need to remove the part where you change the clothes in PlayerGui.