Players.ScxiptedShark.PlayerScripts.LocalScript:29: Players.ScxiptedShark.PlayerScripts.LocalScript:16: attempt to call missing method ‘GetCurrentPage’ of string
I cant seem to find the error. My local script is in StarterPlayerScripts and here is my code which i totally did not rip from the devforum (thanks @Vanniris)
local Players = game:GetService(“Players”)
local UserID = Players.LocalPlayer.UserId
local success, friendPages = pcall(function()
return Players:GetFriendsAsync(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 newFriend = Players:CreateHumanoidModelFromUserId(randomFriend)
newFriend.Parent = game.Workspace
Are you trying to get all a user’s friends? If you are I typically use this to get all of their friends.
local PlayersService = game:GetService("Players")
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
print(FriendIDs)
I do not recommend using CreateHumanoidModelFromUserId() when you could use :ApplyDescription() on an already existing humanoid. That’s something to keep in mind.
task.wait()
local PlayersService = game:GetService("Players")
local LocalPlayer = PlayersService.LocalPlayer
local FriendIDs = {}
local success, fail pcall(function()
local friendsList = PlayersService:GetFriendsAsync(LocalPlayer.UserId)
for page=1,4 do
for _,friend in pairs(friendsList:GetCurrentPage()) do
table.insert(FriendIDs, friend.Id)
end
if page ~= 4 then
local pass,err = pcall(function()
friendsList:AdvanceToNextPageAsync()
end)
if not pass then
break
end
end
end
end)
local Parts = {} -- Your list of parts here
function GetRandomFriend()
return FriendIDs[math.random(1, #FriendIDs)]
end
local SelectedFriend = GetRandomFriend()
local FriendCharacter = PlayersService:CreateHumanoidModelFromUserId(SelectedFriend)
for i,v in pairs(Parts) do
v.CanCollide = false
end
FriendCharacter:PivotTo(Parts[math.random(1, #Parts)].CFrame)
FriendCharacter.Parent = workspace