How to stop the script when button on gui was stopped?

Hi
I have made loading screen but I have try to do like when skip button got clicked
the whole script will get stop except the line that handles button click request
I have to try to use

while not skip do
-- do stuff
end

but the script still continue until it ended
so I wanna have done there are the solution for this

Thank you and sorry for bad English.

is skip a debounce? if so you may just do this

while skip == true do
    -- do stuff
end

If you have the button script and the other scripts separated, then just disable the other scripts with

script.Disabled = true

If they aren’t separated, just separate them its easier to work with 2 scripts and an easy solution than 1 Script and a hard solution.

So i should use BindableFunction right?

while skip ~= false do
-- Code here, and I would use an 'else' inside of here.
end

This runs while it is not false, (aka. when it is true). As said above, use and ‘else’ inside of the code, so it detects when it is false.

how? (this is 30 characters not 4 characters)

Thank you! it worked now
Thank for answer to
@Crrustyy, @whitejackets and @DindinYT37!

So i have try to disabled script and the script is really stop!
Thank you so much

Actually, since the condition is evaluated before anything within the do --- end block runs, the code will only run if skip ~= false, therefore an else block within that won’t ever run (because the former will only run if the condition returns true after evaluated, there won’t be any need for an invert statement within the block), you could still move the else outside.

1 Like

Umm when disabled the script sometime the script still doesn’t stop
Why?

I disabled it from server