so i have a system that takes a random player’s friend character and then loads it in,
but i cant find a way to check if that character has loaded, if you want to do it for the player playing’s character then you just use “CharacterAppearanceLoaded”, but i cant because you need to get the player in order to run this variable or function,
so any help will be appreciated
heres the script (server script) :
local Players = game:GetService("Players")
local function iterPageItems(pages)
return coroutine.wrap(function()
local pagenum = 1
while true do
for _, item in ipairs(pages:GetCurrentPage()) do
coroutine.yield(item, pagenum)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
pagenum = pagenum + 1
end
end)
end
local userId = Players:GetUserIdFromNameAsync(plr.Name)
local friendPages = Players:GetFriendsAsync(userId)
local Friends = {}
for item, _pageNo in iterPageItems(friendPages) do
table.insert(Friends, item.Username)
end
local FriendName = Friends[math.random(1, #Friends)]
local FriendUserId = Players:GetUserIdFromNameAsync(FriendName)
local FriendChar = Players:CreateHumanoidModelFromUserId(FriendUserId)
local FriendHumanoid:Humanoid = FriendChar:FindFirstChildWhichIsA("Humanoid")
local FriendAnimator:Animator = FriendHumanoid:FindFirstChild("Animator")
local FriendRootPart:BasePart = FriendChar:FindFirstChild("HumanoidRootPart")
FriendHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
FriendChar.Parent = Cashier
FriendRootPart.CFrame = NpcStartPositioner.CFrame
-- here is where i need to yeild the script until the friend character has loaded
local WalkAnim = game.ReplicatedStorage.Animations.NpcWalkAnim
local WalkTrack = FriendAnimator:LoadAnimation(WalkAnim)
FriendHumanoid:MoveTo(NpcMoveTo.Position)
WalkTrack:Play()