Friends of friends only

I am trying to make a script which makes it so that only friends of certain people can join, however I can’t find how to do it. Here’s what I have so far:

local whitelist = {000, 000} -- userids here

game.Players.PlayerAdded:Connect(function(plr)
	if not plr:IsFriendsWith(table.find(whitelist)) then
		plr:Kick()
	end
end)
local whitelist = {000, 000} -- userids here

game.Players.PlayerAdded:Connect(function(plr)
if not whitelist[plr.UserId] then
plr:Kick()
end
end)

Should’nt you add another argument to table.find()? maybe you should iterate over every ID and if they’re friends with one ID then don’t kick

Pretty sure you have to loop through every userId:

local whitelist = {000, 000} -- userids here

--decided to pcall the request so in case it fails, it wont allow unauthorized players to join
function IsFriendsWith(plr, userId)
	local result = false 
	local Success, Error = pcall(function()
		result = plr:IsFriendsWith(userId)
	end)
	return (Success and result)
end

game.Players.PlayerAdded:Connect(function(plr)
	local access = false 
	for _, whitelisted in pairs(whitelist) do 
		if IsFriendsWith(plr, whitelisted) then 
			access = true 
			break
		end
	end
	if not access then 
		plr:Kick()
	end
end)
1 Like