How to make npc have player friends apperance?

How do I make NPCs have player friend’s appearances?
I’ve doing a Horror game so I needed for the NPCs player friends appearance

  1. What do you want to achieve? One example for coding then and the exact place I have to put the script example.

  2. What is the issue? Making Player friends appearance.

  3. What solutions have you tried so far? I wanted to find it on Youtube and also in the DevHub but I didn’t find much.
    Can I have some Examples of Coding?

You could get all the player’ friends list by doing this :

--local script
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local PlayersFriends = {} 

local success, page = pcall(function() 
	return players:GetFriendsAsync(localPlayer.UserId) 
end)
if success then
	repeat
		local info = page:GetCurrentPage()
		for i, friendInfo in pairs(info) do
			table.insert(PlayersFriends, friendInfo)
		end
		if not page.IsFinished then 
			page:AdvanceToNextPageAsync()
		end
	until page.IsFinished
end

for i,v in pairs(PlayersFriends) do
 --do stuff, use v.Username for name, and v.Id for their ID
end

Later, you could use this article:

3 Likes

And I put this in the NPC has a script?

No, it’s a local script. You could use it and the article I mentioned to clone the npc and then apply the friend avatar

1 Like
local Game = game
local Players = Game:GetService("Players")
local Workspace = workspace
local NPC = Workspace.NPC
local Humanoid = NPC.Humanoid
local HumanoidDescription = Humanoid.HumanoidDescription

local UserId = 1 --Change this to the desired user ID.

local Success, Result = pcall(function() return Players:GetHumanoidDescriptionFromUserId(UserId) end)
if Success and Result then
	HumanoidDescription:ApplyDescription(Result)
else
	warn(Result)
end

https://developer.roblox.com/en-us/api-reference/function/Players/GetHumanoidDescriptionFromUserId

2 Likes

And where this goes?
I’m not so informed with where some sort of scripts goes.

1 Like