Hello everyone !
I’m currently trying to create my own chat, as i don’t want any trouble with roblox, I want to do the text filtering of my game the right way.
After reading a bit, I understand that if player A is sending a message to player B, it must go like this :
local function getTextObject(message, fromPlayerId)
local textObject
local success, errorMessage = pcall(function()
textObject = TextService:FilterStringAsync(message, fromPlayerId)
end)
if success then
return textObject
end
return false
end
local function getFilteredMessage(textObject, toPlayerId)
local filteredMessage
local success, errorMessage = pcall(function()
filteredMessage = textObject:GetChatForUserAsync(toPlayerId)
end)
if success then
return filteredMessage
end
return false
end
function StringUtil.Filter(plrA, plrB, str)
local messageObject = getTextObject(str, plrA.UserId)
if messageObject then
if toplayer then
messageObject = getFilteredMessage(messageObject, plrB.UserId)
else
messageObject = getFilteredMessage(messageObject, plrA.UserId) <-- not sure about this; if the player send a message in the chat and everyone can see it.
end
end
if not messageObject then
messageObject = "error"
end
return messageObject
end
Do i need to use the same filter if the message is from one player to everyone ? Or is it okay to leave it like this ?