Hi! I have noticed a lot of people have been struggling with the new function TextChatService:CanUsersChatAsync(), so I have decided to make a little tutorial on how to use it. I hope you are able to get something out of this, as I tried my best to explain it. ![]()
If you have any more questions about this or think that I should change something, please let me know.
TextChatService:CanUsersChatAsync() is a new function implemented by Roblox that checks if the users can chat with eachother as a result of the new age checks update.
Fortunately, this is an easy function to understand! You can also use this to detect whether two players can Voice Chat, as the same rules apply.
Parameters
Fortunately, there isn’t much to say about the parameters. They are pretty self-explanatory. The order doesn’t really matter, but it’s best to keep the player you are checking as userIdFrom. This is basically the equivalent of saying:
local x = 5
local y = 10
local function is_x_equal_to_y(_x, _y): boolean
return _x == _y
end
print(is_x_equal_to_y(x, y)) -- false
print(is_x_equal_to_y(y, x)) -- false
userIdFrom: Think of it as a LocalPlayer. You are checking to see if they can chat with the other UserId.
userIdTo: The UserId being checked if they can chat with the other UserId. Basically, your second UserId.
Example usage
In this example, we are checking if the first two users in a server can chat with eachother:
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
-- Create a function that determines whether two users can chat with eachother
local function UsersCanChat(UserId_1, UserId_2): boolean
local success, result = pcall(TextChatService.CanUsersChatAsync, TextChatService, UserId_1, UserId_2)
return success and result or false
end
-- Wait until two users are in the same server
repeat task.wait() until #Players:GetPlayers() >= 2
-- Check if Player1 can chat with Player2
local PlayersInServer = Players:GetPlayers()
local user1, user2 = PlayersInServer[1], PlayersInServer[2]
local canChat = UsersCanChat(user1.UserId, user2.UserId)
local formattedBooleanExpression = canChat and " can " or " cannot "
print(user1.Name..formattedBooleanExpression.."chat with "..user2.Name)
Expected outputs:
Can chat: Player1 can chat with Player2
Cannot chat: Player1 cannot chat with Player2
Limitations
- The function can ONLY be called on the server.
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local player = Players.LocalPlayer
local CanChatWithRoblox: boolean = TextChatService:CanUsersChatAsync(player.UserId, 1)
Errors; Must only be called from server scripts
- Both UserIds you are trying to compare must be in the same server.
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local CanChatWithRoblox: boolean = TextChatService:CanUsersChatAsync(Players:GetPlayers()[1].UserId, 1)
Errors; Both users must be connected to the current server
- Both arguments must be UserIds /
numbers
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local CanChatWithRoblox: boolean = TextChatService:CanUsersChatAsync(Players:GetPlayers()[1], 1)
Errors; Unable to cast Instance to int64
Use cases
This is a really useful function if you are the developer of a Voice Chat game, for example. You could use this system to detect a player’s age group and put them in a server where the user can chat with everyone.
Additionally, let’s say you own a game like Sing It, MIC UP or Neighbors, where communication is crucial. You could use this system to detect whether the LocalPlayer can chat with another user by firing a RemoteFuncton to the server and returning a boolean value. If they can’t, you could display an ImageLabel/TextLabel above their head indicating that the user cannot chat.