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()
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
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:
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:
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.
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.
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.