LocalWE
(WilliApple)
March 19, 2021, 4:37am
#1
Hello! I have recently seen this in the Text and Chat Filtering article on the Developer Hub:
So I attempted to wrap my existing filtering function in a
pcall()
, since I can do an error message on the client saying that there was an error with the chat filter.
The code:
success, filterFunction.OnServerInvoke = pcall(function(plr, unfilteredText)
filteredText = txtSer:FilterStringAsync(unfilteredText, plr.UserId)
return filteredText:GetNonChatStringForBroadcastAsync()
end)
The OG code:
filterFunction.OnServerInvoke = function(plr, unfilteredText)
filteredText = txtSer:FilterStringAsync(unfilteredText, plr.UserId)
return filteredText:GetNonChatStringForBroadcastAsync()
end
The error
If you can help, please let me know. Thanks! WE
You put success, filterFunction
so it expects you to put a string there.
1 Like
LocalWE
(WilliApple)
March 19, 2021, 4:41am
#3
Wait so success
is the string or filterFunction
?
The error is happening because pcall returns 2 values. You could ignore the second variable, but since you put a comma after success
, so it expects the name of the next variable. However, it gets the event connection, so it errors.
LocalWE
(WilliApple)
March 19, 2021, 4:44am
#5
I would do this then? I tried this before and it didn’t work.
filterFunction.OnServerInvoke = pcall(function(plr, unfilteredText)
filteredText = txtSer:FilterStringAsync(unfilteredText, plr.UserId)
return filteredText:GetNonChatStringForBroadcastAsync()
end)
success, failure = filterFunction.OnServerInvoke = pcall(function(plr, unfilteredText)
filteredText = txtSer:FilterStringAsync(unfilteredText, plr.UserId)
return filteredText:GetNonChatStringForBroadcastAsync()
end)
LocalWE
(WilliApple)
March 19, 2021, 4:46am
#7
This was underlined:
success, failure = filterFunction.OnServerInvoke =
Sorry Im pretty new to pcalls()
since none of my code uses them. There is no DevHub article even though there should be one.
I think you should put the pcall into its own function:
function()
local success, failure = pcall(function()
--function stuff
end)
--handle success and stuff
end
1 Like
wc3u
(wc3u)
March 19, 2021, 4:53am
#9
This, but remove the function() end
stuff at the bottom and top.