Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[2] How to do text manipulation?

Asked by 4 years ago

Hello!

I am trying to manipulate the text in my ROBLOX UI in Game as follows

Take the username clydedbeast647

I want the script to display on the textlabel: clyded********

Here is my code:

local Username = game.Players.LocalPlayer.Name
local Filter = '*'
local ExpandTo = (#Username >= 5 and math.random(3,#Username-1) or 3)
local Result = Username:sub(1,ExpandTo)..Filter:rep(7)

script.Parent.Text = "Welcome back " .. Result

It keeps producing a random amount of *, I don't know how to fix it.

1 answer

Log in to vote
0
Answered by 4 years ago
local Username = game.Players.LocalPlayer.Name
local Filter = '*'
local rand
if #Username-1 > 3 and #Username >= 5 then
    rand = math.random(3,#Username-1)
else
    rand = 3
end
local ExpandTo = rand
local Result = Username:sub(1,ExpandTo)..Filter:rep(#Username-ExpandTo)
script.Parent.Text = "Welcome back " .. Result

Fixed it, further details are on Wiki

Ad

Answer this question