Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

theres this code that makes a gui write words and then erase them but it keeps looping how do i fix?

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.

1 answer

✓ Accepted answer

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.

5 comments

0

No problem, remember to accept it as an answer if it works for you! Comment again if you have any questions.

0

why are you using string.len(text), use #text

0

sorry, was away. ive added an end and so im going to test it. sorry about the wait for reply.

0

kk

0

are you sure this works? I've added ends where it wouldn't register an 'end' and it still doesn't work.

This discussion is preserved as it was. New answers, comments, and votes are closed.