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)
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.
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.
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
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.
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)
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?