Found a solution to it
local EndReceiver
local function doFilter(speaker, messageObject, channelName)
if channelName:sub(1,3) == "To " then --Private messaging
if channelName:sub(4,#channelName) == messageObject["FromSpeaker"] and EndReceiver ~= nil then --Server sending message back to sender
if not (game.Players:FindFirstChild(messageObject["FromSpeaker"]):IsFriendsWith(game.Players:FindFirstChild(EndReceiver).UserId)) then
messageObject.Message = filter(messageObject)
EndReceiver = nil
end
else
EndReceiver = channelName:sub(4,#channelName)
if not (game.Players:FindFirstChild(messageObject["FromSpeaker"]):IsFriendsWith(game.Players:FindFirstChild(channelName:sub(4,#channelName)).UserId)) then -- Not friends
messageObject.Message = filter(messageObject)
end
end
else --Not private messaging
messageObject.Message = filter(messageObject)
end
end