r/robloxgamedev • u/ElectricDoge775 • 10h ago
Help Me With Coding Filtering randomly generated text
I'm an amateur scripter, and I have this system that creates a 4-letter string of random characters, using only lowercase letters and numbers, but I am concerned over the possibility that it could generate a swear word. It's unlikely but I want to make sure this doesn't happen. I don't really want to use Roblox's built-in filtering, as the strings need to be generated instantly for each round, and it can cause other issues. What should I do?
2
Upvotes
3
u/Dry-Lingonberry-388 10h ago
TextService:FilterStringAsync()
1
u/Massive_Fondant7439 5h ago
You are right that FilterStringAsync is the wrong tool here. It is async, it needs a real player to filter against, and it exists for text a player typed, not for text your game generated. For a four character code you only need to catch a handful of words, so do it locally.
Three cheap layers, in this order:
You still want the built in filter on anything a player can type, chat and signs and display names, because that is what it is actually for. Codes your system generates just need the local check.
1
u/EducatorOne7130 1h ago
The simplest trick (used by a lot of invite-code generators) is to just remove vowels from your character pool—and usually
0/1/ltoo so players don't misread them:Without
a, e, i, o, u, y, it's practically impossible to spell English swear words, there's zero async delay, and you don't have to maintain a denylist. With 27 chars you still get27^4 = 531,441unique 4-character codes, which is plenty for per-round IDs. (If you still want to be extra safe against leetspeak likefck/sht/cnt, just skip a tiny 5–10 entry blocklist on top.)