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

How do I stop a running script from continuing?

Asked by 6 years ago

Hey guys I need ya'll help. So let's say I have a script like this running:

script.Parent.Event:connect(function()
print("Starting")
wait(350)
--Do more stuff.
end)

But when it is waiting, let's say people lost the game and I don't want the script to run anymore and I want it to stop and go all the way back to the beggining. How do I do that? I'm not sure if you use return but I don't know how to use return anyways.. Note:Making a game where you have to survive until rescue arrives but when the players LOSE the game the script still runs and the bus still is active. How do i stop that?

I really would apreciate who would help me with this

0
you could could a global value somewhere like in lighting, and make the value be true/false after the round. Then add a loop function in that part of the script so it keeps checking if the value is true/false. Nikkulaos 229 — 6y
0
You should use ReplicatedStorage or ServerStorage instead of Lighting for storing things. mattscy 3725 — 6y
0
Good idea. Thanks wilsonsilva007 373 — 6y

2 answers

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

As Nikkulaos said, you can create a variable that you set to true after everyone has lost.

At the top of the script, you can go:

local stopRound = false

Then, the round script can look something like:

stopRound = false
local roundTime = 350
for i = roundTime,0,-1 do
    if stopRound == true then
        break
    end
    wait(1)
end

And when all the players have lost, you can simply go:

stopRound = true
Ad
Log in to vote
0
Answered by 6 years ago

Well, I would recommend a 'if' statement. So

local EventRan = false;
script.Parent.Event:connect(function()
if not EventRan then
EventRan = true
print("Starting")
wait(350)
--Do more stuff.
end
end)

Answer this question