Hello Im having trouble with my tycoon, I want to spawn an npc but I cant get the user id of the owner
My code
local Players = game:GetService("Players")
local OwnerValue = script.Parent.Parent.Values.OwnerValue.Value
local success, friendPages = pcall(function()
return Players:GetFriendsAsync(OwnerValue.UserId)
end)
if not success then
-- remember to handle pcall errors
end
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 += 1
end
end)
end
local userIds = {}
for item, _pageNo in iterPageItems(friendPages) do
table.insert(userIds, item.Id)
end
local randomFriend = userIds[math.random(1, #userIds)]
local HumanoidDescription = Players:GetHumanoidDescriptionFromUserId(randomFriend)
local Rig = workspace.Rig-- replace with your rig