Hi, i’ve been trying to make this chat filter thing for about half an hour. I do not know what this error means, but its on this line:
local FilterText = game:GetService("TextService"):FilterStringAsync(message, Player, Player)
Hi, i’ve been trying to make this chat filter thing for about half an hour. I do not know what this error means, but its on this line:
local FilterText = game:GetService("TextService"):FilterStringAsync(message, Player, Player)
Is Player
variable an object under the game.Players
or it’s player’s UserID?
its the Player itself, not the userid
You need to use the UserId instead of the player object itself.
Do i need to do this for both player parameters
Yeah, do It like this:
local FilterText = game:GetService("TextService"):FilterStringAsync(message, Player1.UserId, Player2.UserId)
that now errors with “Unable to cast double to token”
Make sure that you are using 2 different variables.
Player1 = The player who’s sending the message
Player2 = The player who’s receiving the message
but on the developer website thing it says to use the author for the 3rd parameter if its text that will stay there?
https://developer.roblox.com/en-us/api-reference/function/TextService/FilterStringAsync
The third argument is wrong.
3rd parameter must be either Enum.TextFilterContext.PrivateChat
or Enum.TextFilterContext.PublicChat
or you can leave it blank and let the Roblox deal with it. You would want to leave it black unless you’re making your own chat system separate from Roblox’s chat service.
now errors with unable to cast instance to int64
Did you try to switch Player
to Player.UserId
on the 2nd parameter?
Please provide the modified script. So I know if you did it correctly or not.
yeah i did do that. on both parameters
Okay I checked some things and this should work:
local FilterText = game:GetService("TextService"):FilterStringAsync(message, Player1.UserId):GetNonChatStringForBroadcastAsync()
:GetNonChatStringForBroadcastAsync()
is a function that applies the roblox global filter to a string.
local SendMessage = game.ReplicatedStorage.SendMessage
SendMessage.OnServerEvent:Connect(function(Player, message)
local PlayerID = Player.UserId
print(Player.Name.." Sent Message: "..message)
local FilterText = game:GetService("TextService"):FilterStringAsync(message, Player, Enum.TextFilterContext.PublicChat)
local FilteredText = game:GetService("TextService"):GetChatForUserAsync(FilterText, PlayerID)
SendMessage:FireAllClients(Player, FilteredText)
end)
Switch Player
to PlayerID
on the 2nd parameter.
yay messages send now. but for some reason it still doesnt filter.
does it only filter in the actual roblox?
Yes, the filter doesn’t work in Studio.