Is there a way to make this gui text script shorter? I just need an example of how to do it.
while true do script.Parent.TextColor3 = Color3.new(0, 0, 0) script.Parent.Text = "" wait(0.1) script.Parent.Text = "T" wait(0.1) script.Parent.Text = "Th" wait(0.1) script.Parent.Text = "Tha" wait(0.1) script.Parent.Text = "Than" wait(0.1) script.Parent.Text = "Thank" wait(0.1) script.Parent.Text = "Thank " wait(0.1) script.Parent.Text = "Thank y" wait(0.1) script.Parent.Text = "Thank yo" wait(0.1) script.Parent.Text = "Thank you " wait(0.1) script.Parent.Text = "Thank you f" wait(0.1) script.Parent.Text = "Thank you fo" wait(0.1) script.Parent.Text = "Thank you for" wait(0.1) script.Parent.Text = "Thank you for " wait(0.1) script.Parent.Text = "Thank you for p" wait(0.1) script.Parent.Text = "Thank you for pl" wait(0.1) script.Parent.Text = "Thank you for pla" wait(0.1) script.Parent.Text = "Thank you for play" wait(0.1) script.Parent.Text = "Thank you for playi" wait(0.1) script.Parent.Text = "Thank you for playin" wait(0.1) script.Parent.Text = "Thank you for playing" wait(0.1) script.Parent.Text = "Thank you for playing!" wait(3) end
Yes, you can use a for loop and the sub function of strings.
For loops executes code for every interval provided. For instance for i=1,50 do
for everything between 1 and 50 do the following lines of code.
Sub is used for strings to get certain sections of the string. Say I wanted to get the letters in between 4 and 8 in "Hello World!", I would use string.sub("Hello World!", 4, 8)
and I would get "lo Wo".
For simplicity, we'll make your string "Thank you for playing!" a variable named Msg. Since the for loop needs two numbers, we'll have to use 1 and string.len()
function on the Msg variable. string.len()
will get the length of the string, however #"StringHere"
will return the same result.
local Msg = "Thank you for playing!" while true do for i = 1, string.len(Msg) do script.Parent.Text = string.sub(Msg,1,i) --Since i is always increasing until it gets to its final number, we'll use that as the third argument of string.sub() wait(1/10) --We'll wait a tenth of a second before moving on. end wait(3) --We'll wait three seconds before doing the process over again. end