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)
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)