I’m having an NPC follow a set of lines using a LocalScript, and a RemoteFunction to the server to request this NPC (with the correct player description). Now this RemoteFunction gets called whenever someone walks into a sensor. The problem is that whenever I return the NPC, it weirdly enough gives the HumanoidDescription of the LocalPlayer, and not the player who entered. And yes, I’ve checked exactly what names are sent to the server.
This is basically what happens
https://gyazo.com/6babc1de69e64a91c1f9d937875bbf35
My script:
function PlayerManager.GetLineAvatar()
local AvatarType = GeneralSettings:FindFirstChild("AvatarType")
if AvatarType then
local RealModel = LineCharacters:FindFirstChild(AvatarType.Value)
print(RealModel)
if RealModel then
local CustomSettings = AvatarType:FindFirstChild("CustomSettings")
local FullTable = {}
if CustomSettings.Value == true then
table.insert(FullTable, {RigModel = RealModel, Custom = CustomSettings})
else
table.insert(FullTable, {RigModel = RealModel})
end
return FullTable
end
end
end
function PlayerManager.GetIdFromName(name)
local Id = Players:GetUserIdFromNameAsync(name)
if Id then
return Id
end
end
function PlayerManager.BuildNPC(rigmodel, csettings)
local NewClone = rigmodel:Clone()
local Humanoid = NewClone:FindFirstChild("Humanoid")
if Humanoid then
local RigSettings = csettings
if RigSettings then
for _, v in pairs(RigSettings) do
local SimilarValue = Humanoid:FindFirstChild(v.Name)
if SimilarValue then
SimilarValue.Value = v.Value
else
local NewValue = v:Clone()
NewValue.Parent = Humanoid
end
end
return NewClone
else
return NewClone
end
end
end
function PlayerManager.ApplyDescription(npc, playerid)
local Humanoid = npc:FindFirstChild("Humanoid")
local Description = Players:GetHumanoidDescriptionFromUserId(playerid)
if Humanoid then
Humanoid:ApplyDescription(Description)
end
end
function PlayerManager.CreateNPC(player)
if typeof(player.Name) == "string" then
local RealPlayer = player.Name
local UserId = self.GetIdFromName(RealPlayer)
if UserId then
warn(UserId)
local LineAvatar = self.GetLineAvatar()
if LineAvatar then
for i, v in pairs(LineAvatar) do
if v.RigModel then
print(LineAvatar)
local NPC = self.BuildNPC(v.RigModel)
if NPC then
NPC.Parent = PlayerCache -- Loads the NPC
local success, response = pcall(function()
self.ApplyDescription(NPC, UserId)
end)
if (success == true) then
return NPC
end
NPC:Destroy()
end
end
end
end
end
end
end