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

How to stop previous function, whe second function is started?

Asked by
lolenko 17
3 years ago
rs = game:GetService("ReplicatedStorage")

rs.RemoteEvents.FireAnigilation.OnServerEvent:Connect(function(player, Mouse)
    print("LoL, u will not stop me")
    wait(10)
    print("U lose!")
end)
rs.RemoteEvents.FireAnigilationEnd.OnServerEvent:Connect(function(player, Mouse) 
    print("Yey, i win!")
end)

1 answer

Log in to vote
0
Answered by 3 years ago

You have to have use a variable to keep track of whether the first function should continue or not. For instance, you might set shouldContinue = true when the first function starts running, then shouldContinue = false if it should be cancelled, and then the first function should run if not shouldContinue then return end every time the variable may have changed (after every yield/wait)

Ad

Answer this question