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

How do I make it that the script stops at a certain place? (ANSWERED)

Asked by 4 years ago
Edited 4 years ago

Hello everyone, I'm trying to make it so that my script doesn't run all at once and wait() is not what I want. When I click, all of the script starts, is there any way to stop it once the variable toggle has changed?

local button = script.Parent

local function click()
    local toggle = 1
    if toggle == 1 then
        button.Font = Enum.Font.Arcade
        toggle = 2
    end
    if toggle == 2 then
        button.Font = Enum.Font.Highway
        toggle = 3
    end
    if toggle == 3 then
        button.Font = Enum.Font.Fantasy
        toggle = 4
    end
    if toggle == 4 then
        button.Font = Enum.Font.GothamBold
        toggle = 5
    end
    if toggle == 5 then
        button.Font = Enum.Font.SourceSans
        toggle = 1
    end
end

button.MouseButton1Down:Connect(click)

Thanks, any help would be appreciated

2 answers

Log in to vote
0
Answered by 4 years ago

I know you said that you didnĀ“t want any wait(). However, I am not sure that you have considered this. You could use a repeat until loop combined with wait() to stop your script from running until a certain condition is met.

local button = script.Parent

local function click()
    local toggle = 1

    repeat wait()
        if toggle == 1 then
                button.Font = Enum.Font.Arcade
                toggle = 2
        end

        if toggle == 2 then
                button.Font = Enum.Font.Highway
            toggle = 3
        end

        if toggle == 3 then
                button.Font = Enum.Font.Fantasy
            toggle = 4
        end

        if toggle == 4 then
                button.Font = Enum.Font.GothamBold
                toggle = 5
        end

        if toggle == 5 then
                button.Font = Enum.Font.SourceSans
            toggle = 1
        end
    until --statement is met
end

button.MouseButton1Down:Connect(click)

0
Please remember to accept my answer if you find it useful. AndriusTheGreat 140 — 4y
0
Wait guys, sorry, I'm just stupid, I could've just used elseif, sorry. killerninja81 30 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I could've just used elseif instead of multiple if statements.

Answer this question