Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I stop a running script from continuing?

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

3 comments

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.

0

You should use ReplicatedStorage or ServerStorage instead of Lighting for storing things.

0

Good idea. Thanks

2 answers

✓ Accepted answer

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.