Chat Privacy Settings
Chat Privacy Settings
Roblox supports various privacy settings that users can use to limit who can or cannot communicate with them in game or on the website. When developing a game on Roblox, it is important to make sure all player to player communication respects each player’s privacy settings.
The default Roblox chat already respects privacy settings, but if a game modifies the chat or introduces any other kind of messaging it will have to respect the settings of the user.
CanUserChatAsync
If a user has their privacy setting to none then they should not be able to send or receive messages of any kind in game. This includes chat systems and private messaging. Checking if a player has their setting configured to none can be done with the Chat/CanUserChatAsync
function in the Chat
service. This function takes a Player/UserId
as an argument and returns false if the user’s privacy setting is set to none, otherwise it returns true.
Note that CanUserChatAsync does contact the website which can fail on occasion (due to connectivity errors or other mishaps), so it is important to wrap this function in a pcall. If the pcall fails, the default assumption should be that the function returned false.
-- Declare variables for services local PlayersService = game:GetService("Players") local ChatService = game:GetService("Chat") -- Load in custom chat system local myCustomChatSystem = require(game.ReplicatedStorage.CustomChat) -- Function to call when player added to the game local function onPlayerAdded(player) local playerCanChat = false -- Get whether the player can chat. CanUserChatAsync is wrapped in a -- pcall since it can fail on occasion local success, message = pcall(function() playerCanChat = ChatService:CanUserChatAsync(player.UserId) end) -- If the pcall finished successfully and the player's setting -- allows chat, add them to the cucstom chat system. if success and playerCanChat then myCustomChatSystem:AddPlayer(player) end end -- Bind function to PlayerAdded event PlayersService.PlayerAdded:Connect(onPlayerAdded)
CanUsersChatAsync
In some cases a user will be able to chat with particular users but not others. For example, if a player’s privacy setting is set to Friends Only they should be able to send and receive communication from their friends but no one else. In all cases where communication is attempting to be sent, it is best to use Chat/CanUsersChatAsync
. This function takes two player ids as arguments and returns if the privacy settings of both users allow communication.
Note that like CanUserChatAync, this function needs to be wrapped in a pcall and if said pcall fails then it is safest to assume the two users cannot chat and not send a message.
Keep in mind that if two players can chat, any text communication between must still go through FilterStringAsync.
-- Declare variables for services local ChatService = game:GetService("Chat") -- Setup remote event local customMessageEvent = Instance.new("RemoteEvent", game.ReplicatedStorage) customMessageEvent.Name = "CustomMessageEvent" -- Filters and sends message (if filter is successful) local function sendMessage(sender, recipient, message) local filteredMessage = "" -- Attempt to filter the message local success = pcall(function() filteredMessage = ChatService:FilterStringAsync(message, sender, recipient) end) -- If the message was successfully filtered then send the filtered message if success then customMessageEvent:FireClient(recipient, filteredMessage) end end -- Checks if players can chat with each other and calls sendMessage if they can local function requestSendMessage(sender, recipient, message) local canChat = false -- Get whether players can chat with each other local success = pcall(function() canChat = ChatService:CanUsersChatAsync(sender, recipient) end) -- If pcall finished successfully and the players are allowed to chat, then -- call function to filter and send the message if success and canChat then sendMessage(sender, recipient, message) end end -- Bind requestSendMessage to OnServerEvent customMessageEvent.OnServerEvent:Connect(requestSendMessage)
What to Limit
There are many different ways that players can communicate in game and it is important to understand which cases need to respect privacy settings and which don’t. In general any case where a user can express a custom message intended for communication should respect privacy settings. Labels (such as pet names, store names) or pre-fab message buttons (a thank you emote) do not need to be checked for privacy.
Note that any custom input from a user that gets displayed as text must be filtered.
Features that Should Check Privacy Settings
Custom chat system (or modified versions of the default):
Messaging systems:
Features that Don’t Need to Check Privacy Settings
Pet/NPC names:
Emotes:
Shop names:
A Note on Caching
While it may be tempting to cache the results of whether two players can chat with each other (by storing the result of CanUsersChatAsync), it is not recommended. The Roblox engine already caches the result of the function, and will also be more responsive to changes of a user’s privacy settings. With that in mind, it is best to check with the above functions before sending any chat from one player to another.