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
What do you want to achieve? One example for coding then and the exact place I have to put the script example.
What is the issue? Making Player friends appearance.
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
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