If the title is a bit confusing, basically the code below that makes a GUI write words and erase them, but it keeps looping more than i want. how do i fix this?
TextNum = 1 function loop() while true do local text = script.Parent.Texts["Text"..TextNum].Value local count = string.len(text) for i = 1, count, 1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end wait(2) for i = count, 0, -1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end TextNum = TextNum + 1 if not script.Parent.Texts:FindFirstChild("Text"..TextNum) then wait(3) TextNum = 1 end return loop() end end loop()
So the code above is from a model that works perfectly, it types some and then erases it and loops, but how do i break this code from outside of it like after a certain amount of times? I just have a question on how that works.
You can place a variable into the loop and change it from this:
while true do local text = script.Parent.Texts["Text"..TextNum].Value local count = string.len(text) for i = 1, count, 1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end wait(2) for i = count, 0, -1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end TextNum = TextNum + 1
to this:
local check = 0 while check < 5 do local text = script.Parent.Texts["Text"..TextNum].Value local count = string.len(text) for i = 1, count, 1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end wait(2) for i = count, 0, -1 do script.Parent.Label.Text = string.sub(text, 1, i) wait(0.1) end TextNum = TextNum + 1 check = check + 1
so that it only happens 5 times.