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

Why does my script not change my TextLabel?

I want to make a ... loading TextLabel for my plugin but it doesn't do anything. Here is my script...


local load = script.Parent
local credits = script.Parent.Parent


if credits.Visible == true then
	wait(10)
	credits.Visible = false
end

while true do
	load.Text = (".")
	wait(1)
	load.Text = ("..")
	wait(1)
	load.Text = ("...")
	wait(1)
	load.Text = ("")
end

The credits is the menu and when it disappears.

3 comments

0

Also can someone actually leave an ANSWER instead of a comment?

0

is this a local script?

0

Yup

1 answer

✓ Accepted answer

Instead of repeating the same line of code you could use some useful Roblox functions to make it much easier. string.rep concatenates 'x' times of a string together which then returns that string.

If I wanted to concatenate 'Hello' 3 times together, I could do:

local text = string.rep("Hello", 3)
print(text)

--Output:
--HelloHelloHello

We can use this in the while-loop to form the animated ellipsis effect:

local count = 0 --start at 0
local text

while true do
	text = "Loading"..string.rep(".", count)
	
	print(text)--for testing

	count = (count + 1) % 4
	wait(1)
end

On line 6, we use to calculate the count we're on by getting the remainder of count divided by 4 (Search the modulus operator for more).

####So if we were on count 3. We add 1 to get 4 and divide by 4 which leaves no remainder making count 0 again.


The reason your Text may not be changing could be found by adding a few prints() to debug what does run. Like inside the if-statement on line 5 or checking to see your variable paths are right.

Remember that the while-loop is infinite so you will need something to break it.

The finished script should look something like:

local loadLabel= script.Parent

local count = 0
while true do
	loadLabel.Text = string.rep(".", count)

	count = (count + 1) % 4
	wait(1) --eh
end

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