You can use the String manipulation methods :Sub() and :Rep(). These two functions are short for Substitute and Repeat.
By deriving a number from a Ternary statement, we can randomly select a point in their name to cut off from relative to the length of their Username. We can then supply said number into the substitution method to tell our code to get the piece of their Name from the beginning to point n.
After we get our snippet, we concatenate the rest of the asterisks onto the snippet by devising how much space is left of their Username, and respectfully duplicating them together until they add up the maximum character length.
local Username = "ExamplePlayerUsername"
local Filter = '*'
local ExpandTo = (#Username >= 5 and math.random(3,#Username-3) or 3)
local Result = Username:sub(1,ExpandTo)..Filter:rep(#Username-ExpandTo)
print(Result)
1 comment
I’ve answered your comment below.