I want to filter messages which weren’t sent by a player. But, the FilterStringAsync method of TextService requires a user id as the second parameter.
I have tried providing the user id of a random player in the server, but the messages may be filtered unneccessarily if the player uses safe chat and there may be other issues associated with doing so.
Why would you need to filter non user-generated content?
Why would you need to filter anything when the server is empty and no player is in it to see said content?
Basically for you to filter anything you need an observer(else what’s the point of even showing any text?) and if you have an observer, just filter the text according to their id.
I may be wrong but I think the userId must be in the game in order to be used. I assume such measures are taken just in case somebody spams the API to get the age group of players(by using specifically crafted strings).
Fetch the text from ChatGPT unfiltered, store it on the server, and don’t show it anywhere.
Make a player send a “text request” to the server when the text should be visible to them(or a bit before that).
The server that has the unfiltered version of the string, filters it using the user id of the player requesting it and sends them back the filtered response.
The response is displayed on a UI or something.
Also, you can cache filtered versions on the server(for example cache filtered response 1 from ChatGPT for <13 age group) so you don’t have to make multiple requests for filtering the same thing for the same kind of players.
I Have A, Better Idea, If That String Is A Part Of A GUI Or Something, Use A LocalScript In That So Each Viewer Sees It Has A Different Prespective, So,
If You Have A string that contains bad words u need to filter it, so in that localscript, u can use that user’s User Id. For Example TextService:FilterStringAsync(RandomTextLable.Text, game.Players.LocalPlayer.UserId) So Text Will Be Seen Differently Between A <13 Player And <16 Player.
:FilterStringAsync() is deprecated on LocalScripts and will be removed soon. Instead, as @NyrionDev suggested, they should implement it as a player sending a request to the server, the server fetching the text, and filtering it by using the requester player’s UserId.
I probably wasn’t clear enough, the issue is that there is a single prompt and each time a new response is generated, but the players don’t give the prompt.
What I’m mentioning here is perspective and observation. Basically you can store the unfiltered result on the server as a piece of information as long it’s not visible to the client and give the client the filtered result through communication by using remotes. Example of this communication would be:
Server gets the unfiltered message of ChatGPT but doesn’t show it anywhere.
Server sends a “flag” to all the players that it got the message(but not the message itself).
The clients send a request to the server to receive the message.
The server filters the message according to the UserId of whoever is requesting it.
The server returns the filtered message to that specific client.
After that client receives it a local script puts it on a UI or whatever piece of visual information only that specific client can see(because when local scripts make changes, they aren’t replicated to the server, for example, if they change a billboard UI text it won’t be shown to the other clients so you’re safe).
Also, you can simplify this and only make a single filter request on the server per ChatGPT response but the cost of this is that all the clients will have the same properly filtered text(which may use an aggressive filter to protect younger audiences), if you chose that path you can use the GetNonChatStringForBroadcastAsync() function of TextFilterResult and cache the result on the server in case multiple people request it(so you don’t have to filter the same thing multiple times).