Im trying to make a custom chat and when I filter the messages on a server script, it sends nil?
The text printed will give me the text inputted
But the filtertextresult printed gives me nil?
local TextChatService = game:GetService("TextService")
game.ReplicatedStorage.ChatMessageSend.OnServerEvent:Connect(function(player, text)
local FilterTextResult = ""
local success, errorMessage = pcall(function()
FilterTextResult = TextChatService:FilterStringAsync(text, player.UserId)
end)
task.wait(0.05)
if success then
game.ReplicatedStorage.ChatMessageEvent:FireAllClients(player, FilterTextResult)
else
warn(errorMessage)
end
end)
local TextService = game:GetService("TextService")
local function getTextObject(message, fromPlayerId)
local textObject
local success, errorMessage = pcall(function()
textObject = TextService:FilterStringAsync(message, fromPlayerId)
end)
if success then
return textObject
else
warn(errorMessage)
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
else
warn(errorMessage)
end
return false
end
game.ReplicatedStorage.ChatMessageSend.OnServerEvent:Connect(function(player, text)
if text == "" then
return
end
local messageObject = getTextObject(text, player.UserId)
if not messageObject then
return
end
local filteredMessage = getFilteredMessage(messageObject, player.UserId)
game.ReplicatedStorage.ChatMessageEvent:FireAllClients(player, filteredMessage)
end)