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

Why does my script not change my TextLabel?

Asked by 5 years ago

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.

0
Also can someone actually leave an ANSWER instead of a comment? zboi082007 270 — 5y
0
is this a local script? WideSteal321 773 — 5y
0
Yup zboi082007 270 — 5y

1 answer

Log in to vote
1
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

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
Ad

Answer this question