Loading Screen Complications

Note I am a beginner in scripting
Ok so been playing around with new code. And using the loop knowledge @ijmod gave me. I made this code.

local bar = script.Parent.Loadin1.BarHolder.MainBar
	
for i = 1,13 do
	wait(0.25)
	script.Parent.Loadin1.Main.Text = "Loading"
	wait(0.25)
	script.Parent.Loadin1.Main.Text = "Loading ."
	wait(0.25)
	script.Parent.Loadin1.Main.Text = "Loading .."
	wait(0.25)
	script.Parent.Loadin1.Main.Text = "Loading ..."
	wait(0.25)
	bar:TweenPosition(UDim2.new(0, 0, 36, 0)
end

But I am getting a error.


Its says line 13 now instead of 12
But thats not the main problem

Main Problem

I am trying to make the size go from

0,0 and 0,58

To plus 36 every time

0,36 and 0,58
0,72 and 0,58
etcā€¦

All using TweenSize.

This is what I am having a problem with

1 Like

Consider using loops to make your text animations more efficient and functions to simplify copy/pasted code. Something like this will work much more effectively:

local label = script.Parent.Loadin1.Main

local function setText(text, yieldTime)
     --text [string] = what the loading text should say
     --yieldTime [number] = how long it should wait until the next piece of code can run
     label.Text = text
     wait(yieldTime)
end

local function loadingScreen()
     for i = 1, 2 do --2 represents how many times you want the Loading dots to repeat.
          setText("Loading .", 0.5)
          setText("Loading ..", 0.5)
          setText("Loading ..", 0.5)
     end
     wait(1)
     setText("Waiting For Game", 1)
     setText("Giving Cops Keycard", 1)
     setText("Getting Cells Ready", 1)
     setText("Bank Opening", 1)

     script.Parent.Loadin1.Main2.Text = "Done"
     script.Parent.Loadin1.Main.Text = "Done Loading"

     script.Parent.Enabled = false
end)

loadingScreen()
2 Likes

Sorry

As I said I am new to scripting can you explain this.

Sure thing! So starting off with our setText function:

local function setText(text, yieldTime)
     --text [string] = what the loading text should say
     --yieldTime [number] = how long it should wait until the next piece of code can run
     label.Text = text
     wait(yieldTime)
end

You can learn more about functions here: Functions | Documentation - Roblox Creator Hub

But to sum it up, the function takes in 2 parameters, text (a string), and yieldTime (number). The text parameter changes what the outputted text is. The yieldTime parameter just waits a certain number of times until the code below can be ran. It was added because your code contained a lot of repeated code that couldā€™ve been simplified to make your code cleaner.

The loadingScreen function is where everything is put together. We start with:

You can learn more about for loops here: Introduction to Scripting | Documentation - Roblox Creator Hub

But the general idea here is we create a variable, i with the initial value of 1, hence the i = 1, and we want to ITERATE the variable i x amount of times until it reaches our goal, in this case, 2. That is the reason you see the format: for i = 1, 2.

Everything inside of the for loop is then repeated TWICE because we set our goal as 2. If we were to set our goal to 10, it would repeat 10 times. To avoid weird looking sequential code such as:

script.Parent.Loadin1.Main.Text = "Loading ."
	wait(0.5)
script.Parent.Loadin1.Main.Text = "Loading .."
	wait(0.5)
script.Parent.Loadin1.Main.Text = "Loading ..."
	wait(0.5)
script.Parent.Loadin1.Main.Text = "Loading ."
	wait(0.5)
script.Parent.Loadin1.Main.Text = "Loading .."
	wait(0.5)

AND repeated code, we can use our setText function and pass the arguments of whatever we want our text to be as well as the wait time. Since you repeated your ā€œLoading .ā€ twice, it will do the exact same thing except with less code. Since we added a wait function in our setText function, it will YIELD however many seconds we put in our arguments. Since you wanted the text to wait 0.5 seconds before changing the text again, we can pass the argument 0.5 as our yieldTime.

After the end statement that closes off our for loop, we can set the text AGAIN, but this time, we can change it to be the other comments that arenā€™t the ā€œLoading .ā€ ones. We set these with the wait time of 1 because that is what you specified in your code.

setText("Waiting For Game", 1)
     setText("Giving Cops Keycard", 1)
     setText("Getting Cells Ready", 1)
     setText("Bank Opening", 1)

Iā€™m not the best explainer for code by any means, but I highly suggest that you read over the two links I mentioned above to see more examples of what I just showed you with simpler context.

2 Likes

So here

I need to set these?

And I also updated the post a bit

Thank You for the help.

Thank You for this.

This code makes much more sense now.

You can CALL the function and set the arguments to be whatever you like.

setText("Testing 100", 100)

We already created the function, so we just need to call it.
The code I showed above is an example of how you can use the setText function. The ā€œTesting 100ā€ is what the text will say once the code runs, and the 100 is how long the program will wait until anything under the code will execute.

1 Like

So I tried the code in game and it didnā€™t work.

Instead of doing that unnecessarily, you can use:

game:IsLoaded()

so instead of forcing the player to have a loading screen, it serves a use.
Also, for tweening the frame, you can use:

Frame:TweenPosition(UDim2.new(0, 0, 1, 0)
-- Play around with the values a little bit
1 Like

Updated Post thanks for you help.

You forgot to put another closing bracket ) at the end of your code

1 Like

I think the big problem is though that my TweenService is not working.

	bar:TweenPosition(UDim2.new(0, 0, 36, 0)

This is your problem.

	bar:TweenPosition(UDim2.new(0, 0, 36, 0), "Out", "Linear", .5, true)

This is your solution.

1 Like

Wait a minute shouldnā€™t be TweenSize?

Huh? Iā€™m not really following, all I know is thatā€™s how you write down TweenPosition correctly. The same can be said for TweenSize.

1 Like

This is what I mean. I am trying to make a loading bar.

local max = 100
local current = 0
while wait() do
current = current + 1
size = current/max
if current >= max then
break
end
end

Then you just set the bars X size to ā€˜sizeā€™.

Huh? I am not following now.

This is the Current code.

How will this look in There?

It was just an example of how you should do things.

Thers no way to do like

bar:TweenSize(UDim2.new(+0, +36, +0, +0), "Out", "Linear", .5, true)

?