How can I get the owner's friends

I am trying to make an admin system with an option to automatically give the owner’s friends admin, I have tried to search on the wiki about get friend async but everything I have tried isn’t working.

local admins = {
	{
		ID = 1578920035,
		Rank = 5
	},
}

local friendCommands = true
local friendCommandRank = 4

game.Players.PlayerAdded:Connect(function(player)
	if friendCommands == true then
		for i, friendUserId in pairs(game.Players:GetFriendsAsync(player.UserId):GetCurrentPage().UserId) do
			table.insert(admins, {ID = player.UserId, Rank = friendCommandRank})
		end
	end
end)

When a player joins the game, you could use Player:IsFriendsWith() to check if the player is friends with the owner. I’m pretty sure it returns a boollean, so you can do

if player:IsFriendsWith(00000) then
—[[table insert stuff]]

I’m on mobile, formatting is kinda hard on mobile. :flushed:

I have tried it already but that was in a different format so I will get back if it works.

Hm, it does work but the problem is that it is still giving my friends admins even when the value is false.

This might be unnecessary, but maybe you could add an index to the table every time a player joins regardless of whether or not they’re friends with the owner, and remove the index if the player is not friends with the owner.

1 Like

Can you show your latest code that you have used now?

game.Players.PlayerAdded:Connect(function(player)
	if friendCommands == true then
		if player:IsFriendsWith(game.CreatorId) then
			table.insert(admins, {ID = player.UserId, Rank = friendCommandRank})
		end
	end
end)

If the game.CreatorID of the game is a group id, then IsFriendsWith won’t work because obviously groups can’t have friends.

Perhaps you could just make a variable called “creatorID” or something like that and leave it up to you/the person using that script to configure the creator ID.

local creatorID = 0000000
if player:IsFriendsWith(creatorID) then
—stuff
end

Yes I have tried with:

if game.CreatorType == Enum.CreatorType.User then

It doesn’t make a difference though. Any suggestions?

2 Likes

If you want to get the game creator UserID just use this

game.creatorid

Yes I used that in the is friend bit.

What if he were to use http service? It is more complicated but works nonetheless?