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

How to loop through numbers in a text label?

Hello! I am trying to make a text label say: Lodaing assets (1%) Lodaing assets (2%) Lodaing assets (3%) etc. but I get the following error: Players.gamer19610.PlayerGui.Menu.GamePopup.Text3.LocalScript:10: attempt to call a number value  -  Client  -  LocalScript:10

My code is:

local Percent = 0

while Percent < 100 do
	script.Parent.Text = "Loading Assets (" .. Percent "%)"
	wait(0.1)
	Percent = Percent + 1	
end

print("Assets Loaded!")

Sorry for any bad writing!

NOTE: THIS IS NOT A REQUEST, I AM SIMPLY WONDERING HOW TO FIX THE ERROR. IF ANYONE THINKS ITS A REQUEST ILL TAKE THE POST DOWN IMIDEATLY

2 answers

✓ Accepted answer

You forgot to put .. at line 4:

-- you have:
script.Parent.Text = "Loading Assets (" .. Percent "%)"

-- should be:
script.Parent.Text = "Loading Assets (" .. Percent .. "%)"

The more professional solution tho would be string.format, read that blue article to understand it, it basically formats in a string, in your case it would look like this:

local Percent = 0

while Percent < 100 do
	script.Parent.Text = string.format("Loading Assets (%d%%)", Percent)
	wait(0.1)
	Percent += 1 -- += is same as Percent = Percent + 1 but more comfortable

https://ibb.co/ygrzw7g -- IMAGE SHOWS HOW TO SETUP

So for this you have a textlabel wich says LOADING ASSETS... And one textlabel wich will display your loading number

Intvalue (shown in the picture)

local Label = script.Parent.Parent.Label
local NumberInt = script.Parent.NumberInt

local LoadingPercent = 0

while LoadingPercent < 100 do
	
	LoadingPercent = LoadingPercent + 1
	NumberInt.Value = NumberInt.Value + 1
	
	Label.Text = NumberInt.Value
	wait(.1)
end

2 comments

0

Oh ty!, it stil dosent work sadly and its giving me the same error

0

Ty!, imKirda already posted a working answer but ill be sure to try this method too in the future!

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