Need help with a GUI

So I’ve run into an issue. I’m trying to make a loading text label that adds one period every second but resets at 3.
(local script):

local text = script.Parent.Text
local counter = 0

while true do
wait(1)
text = text…“.”
counter = counter + 1
print(counter)
end
?if counter == 3 then
text = “Loading”
counter = 0
end

The counter goes up every second but the text never changes and the if statement at the bottom doesn’t work either. Can anyone help please?

2 Likes

The code below at the while loop will never run because the loop will never end.
Instead put the code below the loop inside the loop, this way the if statement will run and the counter should reset back to 0.

Hope this helps!

local text = script.Parent.Text
local counter = 0

while true do
   wait(1)
   text = text.."."
   counter = counter + 1

   if counter == 3 then
       text = "Loading"
       counter = 0
   end
end

(Made some fixes into your code)

4 Likes

Thanks that fixes the issue with the counter. But the issue about the text not changing is still there. Can you help me with that as well?

Just noticed that I forgot about the TextLabel.Text property… Thanks for pointing out!

local text = script.Parent.Text
local counter = 0

while true do
   wait(1)
   text.Text = text.."."
   counter = counter + 1

   if counter == 3 then
       text.Text = "Loading"
       counter = 0
   end
end
1 Like

That didn’t seem to fix anything. the counter doesn’t work anymore, and the text still doesn’t change. I think it might be better to make it

text = “Loading” + “.”

or something like that. I just don’t know how that would be formatted into the script.

I’m not sure if the text variable is a TextLabel or a Text property, so I’m guessing you have another variable for the actual text and the TextLabel.

Something like this:

local textLabel = script.Parent.TextLabel -- pointing to your TextLabel
local text = "A loading text" -- any string should do

while true do
   wait(1)
   textLabel.Text = text.."." -- Should change the text to "A loading text."
   counter = counter + 1

   if counter == 3 then
       textLabel.Text = "Loading" -- Changes the text to "Loading"
       counter = 0
   end
end
1 Like

this changes the text to “A loading text.” but doesn’t give it a period every second. I know why, but i don’t know how to fix it.

do you want to add a period every second? (1 period in first second, 2 period in second second).
Please clarify.

2 Likes

Yes. I also want it to reset every 3 seconds.

local textLabel = script.Parent.TextLabel
local text = "Loading"
local counter = 0

while true do
   task.wait(1)
   textLabel.Text = text.."."
   counter += 1

   if counter == 3 then
       textLabel.Text = "Loading"
       counter = 0
   end
end
2 Likes

If you mean adding a period 3 times then resetting once the counter hits 0, then it should be like this:

local textLabel = script.Parent.TextLabel -- pointing to your TextLabel
local periods = {".","..","..."}
local counter = 0

while true do
   wait(1)

   textLabel.Text = `Loading {periods[counter+1]}` -- String interpolation
   counter = counter + 1

   if counter == 4 then -- 4, due to the counter stopping at the 2nd item of the array
       textLabel.Text = "Loading" -- Changes the text to "Loading"
       counter = 0
   end
end

(Tested, working correctly)

3 Likes

Thank you, this works. Only problem was there wasn’t

local counter

and that broke the script, but i fixed it. Thank you for all your help!

2 Likes

mark the post as the solution so we know its solved

Done

(this is just additional text so i can publish this reply lol)

1 Like

here’s a shorter version if you wanted it:

local textLabel = script.Parent.TextLabel
local counter = -1

while task.wait(1) do
    counter = counter + 1
    textLabel.Text = "Loading"..string.rep(".",math.fmod(counter,3)+1)
end

also I recommend working with the output open to make it easier to debug (if you don’t already)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.