need help filtering text, using events to pass text to server and then filtered result back to client. I dont know why it’s always passing back nil, the player or Instance. Note that the “hi” is what was actually in the text box.
client:
InfoBox.FocusLost:Connect(function()
task.wait(0.1)
if InfoBox.Text ~= nil then
print(InfoBox.Text)
SendForFilter_Info:FireServer(player, InfoBox.Text)
end
end)
FilteredText_Info.OnClientEvent:Connect(function(player, result)
print(tostring(result), result)
InfoBox.Text = result
BasicInfo.Value = result
end)
server:
SendForFilter_Info.OnServerEvent:Connect(function(player, text)
print(text)
local FilteredText
local success, err = pcall(function()
FilteredText = TextService:FilterStringAsync(text, player.UserId)
end)
if not success then
warn(`[SpriteService] Error filtering text: {text}. UserId: {player.UserId}`)
FilteredText_Info:FireClient(player, "Error filtering text")
else
local FilteredString = FilteredText:GetNonChatStringForBroadcastAsync()
print(FilteredString)
FilteredText_Info:FireClient(player, FilteredString)
end
end)
The reason this code does not work is because you are getting “Player” as the string on the client, instead of “result”. This is happening because OnClientEvent does not automatically take the Player as a parameter on the client. To fix it, either remove the “Player” parameter from the client, or pass the player twice from the server (Ex: FilteredText_Info:FireClient(player, player, FilteredString) ).
But on the server it is printing the correct text.
local FilteredString = FilteredText:GetNonChatStringForBroadcastAsync()
print(FilteredString) --> whatever the filtered result is
FilteredText_Info:FireClient(player, FilteredString)
Your main issue is when you receive the OnClientEvent. There should only be one parameter in the OnClientEvent, which is FilteredString. To fix this, simply remove the first parameter which is “player” (Do this on the local script in which the event gets received!)