I have a script to filter a textbox upon pressing a button.
local filteredtext = remote:InvokeServer(textbox.Text) textbox.Text = filteredtext
The part above is causing this error:
Players.hpenney2.PlayerGui.ScreenGui.Check.LocalScript:13: bad argument #3 to 'Text' (string expected, got nil)
Specifically, textbox.Text = filteredtext
is causing the error.
This is the filter script:
local filter = game:GetService("TextService") local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("Filter") remote.OnServerInvoke = function(plr, unfilteredtext) local success, errorMessage = pcall(function() local filteredtext = filter:FilterStringAsync(unfilteredtext, plr.UserId) end) if not success then warn("Error filtering text:", unfilteredtext, ":", errorMessage) wait() local success, errorMessage = pcall(function() filteredtext = filter:FilterStringAsync(unfilteredtext, plr.UserId) end) elseif success then return filteredtext end end
Something I noticed is that before the server is even invoked (the server is invoked once a button is pressed), this warn shows up in the output:
Error filtering text: nil : Argument 1 missing or nil
Which means the filter is trying to run before the button is even pressed, which it can’t because the argument (textbox.Text
, which is, well, a TextBox’s text) isn’t passed to it until it’s invoked.
How can I fix this?
EDIT: I tried adding the following code to the top of the filter script:
if unfilteredtext == nil then unfilteredtext = "" end
This makes the warn go away, but the error still occurs upon pressing the button.
EDIT 2: Switching to using a RemoteEvent also does not fix this issue.
Solved! Apparently, FilterStringAsync()
does NOT return a string, but rather returns a TextFilterResult. This can then be filtered with one of three functions, which I used GetNonChatStringForUserAsync()
for my case.