Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
DemGame 271 Moderation Voter
3 years ago

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.

0
No problem, remember to accept it as an answer if it works for you! Comment again if you have any questions. DemGame 271 — 3y
0
why are you using string.len(text), use #text incapaz 195 — 3y
0
sorry, was away. ive added an end and so im going to test it. sorry about the wait for reply. Xx_LightningX 2 — 3y
0
kk DemGame 271 — 3y
0
are you sure this works? I've added ends where it wouldn't register an 'end' and it still doesn't work. Xx_LightningX 2 — 3y
Ad

Answer this question