I am making an admin system and I want an option for the owner’s friends to have admin.
local admins = {
{
ID = 1578920035,
Rank = 5
},
}
local friendCommands = true
local friendCommandRank = 4
game.Players.PlayerAdded:Connect(function(player)
if friendCommands == true then
if player.UserId == game.CreatorId then
local friends = game.Players:GetFriendsAsync(player.UserId)
for i, v in pairs(friends) do
table.insert(admins, {ID = i.UserId, Rank = friendCommandRank})
end
end
end
end)
Not sure if I’m doing something wrong but I’ve searched the dev forum and I can’t find anything else on the wiki about get friend async.
Looking at the FriendPages it looks to me that i.UserId should be changed to i.Id as UserId does not exist in the FriendPages object. One more thing to note is you should probably check that the place is owned by a player not a group. You can do this by adding this by changing
if player.UserId == game.CreatorId then
into this
if game.CreatorType == Enum.CreatorType.User and player.UserId == game.CreatorId then
EDIT:
I just noticed it does not appear like you are using GetCurrentPage() which means the loop will not work. I’d recommend using this function from the devhub which you can just put at the top of the script.
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
And then you can change your pairs loop to this
for item, pageNo in iterPageItems(friendPages) do
table.insert(admins, {ID = i.UserId, Rank = friendCommandRank})
end
game.Players.PlayerAdded:Connect(function(player)
if friendCommands == true then
if game.CreatorType == Enum.CreatorType.User then
if player:IsFriendsWith(game.CreatorId) then
table.insert(admins, {ID = player.UserId, Rank = friendCommandRank})
end
end
end
end)