local l={}function CheckFriendship(b,A)if b==nil or A==nil or l[b.Name]==nil or l[A.Name]==nil then return false end local L=false local K=false for l,b in pairs(l[b.Name])do if b==A.userId then L=true break end end for l,A in pairs(l[A.Name])do if A==b.userId then K=true break end end if L==true and K==true then return true else return false end end game.ReplicatedStorage.RemoteFunctions.SendFriendsOnlineData.OnServerEvent:connect(function(b,A)if type(A)=="\116\097\098\108\101"and#A<=200 then for l,b in pairs(A)do if type(b)~="\110\117\109\098\101\114"then return end end l[b.Name]=A end end)game.ServerStorage.RemoteFunctions.PlayersAreFriends.OnInvoke=function(l,b)return CheckFriendship(l,b)end game.Players.PlayerRemoving:connect(function(b)l[b.Name]=nil end)


local friendlists = {} --Key: person's username. Value: table of online friends' user IDs

function CheckFriendship(caller,target)
	if caller == nil or target == nil or friendlists[caller.Name] == nil or friendlists[target.Name] == nil then return false end
	local f1 = false
	local f2 = false
	for _,v in pairs(friendlists[caller.Name]) do
		if v == target.userId then
			f1 = true
			break
		end
	end
	for _,v in pairs(friendlists[target.Name]) do
		if v == caller.userId then
			f2 = true
			break
		end
	end
	if f1 == true and f2 == true then
		return true
	else
		return false
	end
end

game.ReplicatedStorage.RemoteFunctions.SendFriendsOnlineData.OnServerEvent:connect(function(plr,tbl) --client should send a table of all friend userIDs
	if type(tbl) == "table" and #tbl <= 200 then
		for _,v in pairs(tbl) do
			if type(v) ~= "number" then return end
		end
		friendlists[plr.Name] = tbl
	end
end)

game.ServerStorage.RemoteFunctions.PlayersAreFriends.OnInvoke = function(caller,target)
	return CheckFriendship(caller,target)
end


game.Players.PlayerRemoving:connect(function(plr)
	friendlists[plr.Name] = nil
end)
