How can I make this script restart and stop when a event is fired?

Hello Developers! I have a script which fires an event when the round starts. Then another script picks up this event and does its thing, and that works fine. But the script also fires an event when a round ends, how can I make my other script pick up this event and restart from line 1. So that when the start event gets fired it starts again. So to recap, The game starts, the script does its thing, but when the game ends, I want the script to restart itself at line 1.
Here is my script which receives the events:

local event = game.ReplicatedStorage.Event

local Waves = game.ServerStorage.Waves

local function onEvent()

wait (5)

local Wave1 = Waves.Wave1:clone()

Wave1.Parent = workspace

wait (15)


local Wave2 = Waves.Wave2:clone()

Wave2.Parent = workspace

wait (20)


local Wave3 = Waves.Wave3:clone()

Wave3.Parent = workspace

wait (30)


local Wave4 = Waves.Wave4:clone()

Wave4.Parent = workspace

wait (35)


local Wave5 = Waves.Wave5:clone()

Wave5.Parent = workspace

wait (40)


local Wave6 = Waves.Wave6:clone()

Wave6.Parent = workspace

wait (40)


local Wave7 = Waves.Wave7:clone()

Wave7.Parent = workspace



local Wave8 = Waves.Wave8:clone()

Wave8.Parent = workspace



local Wave9 = Waves.Wave9:clone()

Wave9.Parent = workspace



local Wave10 = Waves.Wave10:clone()

Wave10.Parent = workspace

wait (60)




So what edit do I make so that it it restarts at line 1 when an event gets fired?

1 Like

Also, if you would like the script that sends the events, you can let me know.

Also, (again) if me giving you the name of the events or scripts or anything else will help, then just ask!

The script I am using for this always does work the way it is supposed to but dosent end.

I don’t really understand what exactly you want to achieve. You have a script (call it scriptA) that fire an event when the round starts and ends. And you have another script (call it scriptB) that currently only pickup when the starts event fired.

What i don’t understand

You want the scriptB to pickup the ends event to restart, but

Why would you need the ends event if the scriptB restart the round itself?

Anyway, can’t you just do the same thing as you do for handling the starts event?
And also if the round is run from the scriptB how can the scriptA know when it ends in order to fire the ends event?

Perhaps you can elaborate more with example of the scriptA that fire the starts and ends events?

Sorry no, script A does the round stuff and script B picks up the events. I want script B to restart at line 1 when Script A fires “Restart Round” event.

You could have Script B have the entire script “encompassed” by the Event. So you’d have Script B have the first line be the Event variable, then after that have the code inside of it to do everything, and then at the end of the script finish the Event connect function.

Like this:

Script B:

local event = -- Path to event

local function restartScript()
-- Your entire script here (besides the event of course)


Also, I’m not sure what kind of event you’re using, is it a Bindable Function or Event? But anyhow, you’d need to customize the “event:Connect(restartScript)” part to work for whichever type of event you’re using.

I hope it works out! Let us know if something goes wrong.

Im using a bindable event. Also I would like it to start on a eventA and restart even if its in the middle of the script on eventB.

Your post is what I have right now which doesn’t work. Refer to the post above for what I want.

I dont need help anymore with this topic. But you can still reply to help other developers!