Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I do this certain type of text manipulation in ROBLOX?

I want to display a player's username by using covering some parts For example: take the username clydedbeast647 it would show: Hi clydedb* * * * * * * (without spaces)

This would obviously depend on the username, but the minimum letters shown would be the 1st three.

1 comment

0

I’ve answered your comment below.

2 answers

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)

6 comments

0

Thanks so much! It worked! How do I change how much it replaces with the * please?

0

The :rep() method contains a single argument, that of which defines how many times it should repeat. Currently, a mathematical formula sit’s in it’s place to find out the exact number of characters left in their name and add the asterisks respectfully. Just write Filter:rep(7) if you want and it will replicate 7 times.

0

If this answer helped, don’t forget to accept it!

0

Yes, thanks! However I do not have the amount enough of rep hehe

0

I did as you asked, but I keeps producing a random amount of astericks every time I join the game, there is never a fixed number

0

What did you write,

You could simply use concatenation, string.rep and string.sub to achieve this. For example:

local function censorString(str, amount)
	local uncensoredSection = str:sub(1, amount)
	local censoredSection = string.rep("*", #str - amount)
	return uncensoredSection .. censoredSection
end

Hope this helps!

1 comment

0

Hi! I tried this, and it did not work. Do I need to declare any additional variables?

This discussion is preserved as it was. New answers, comments, and votes are closed.