#Game over system

255 messages · Page 1 of 1 (latest)

fiery crater
#

in this tutorial i was watching, it uses "Break" To stop the wave system in the tower defense, but when i use it in the same way, it says it needs to be placed inside a loop

jolly nexus
#

are you sure your following the tutorial right

fiery crater
#

yea i did everything they did, everything else works except for this part

#

@jolly nexus do you know what i could do to fix it?

jolly nexus
#

lemme

#
print("Game Over")
#

you dont need the if and break

#

because the repeat until checks if the game is over already

fiery crater
#

so do i just delete "IF gameOver then"

#

or

jolly nexus
#

yea

fiery crater
#

so just print game over?

jolly nexus
#

yes

#

remove the end

#

underneath game over

fiery crater
#

ok

#

but how do i make it so that when the gameover event happens, the waves stop happening

jolly nexus
#

bro i have no idea what that is

#

you have only showed me a little bit of the script

fiery crater
#

here lemme ss it

jolly nexus
#

it should be in the tutorial

#

just check the tutorial

fiery crater
#

thats what the break thing was for

#

to stop the wave system

jolly nexus
#

what wave system

#

the repeat until?

fiery crater
#

yea, a wave of enemys coming out

#

when the base health is 0

#

it will stop them from spawning

#

thats what the break was for

#

to stop the waves from happening

jolly nexus
#

well it repeats until the game stops

#

so you dont even need the break

fiery crater
#

it repeats until all 15 waves are done

jolly nexus
#

yea idk

#

make sure your really really getting the tutorial right

fiery crater
#

aight

quiet creek
#

look at this

#

put it isnide of the repeat loop

fiery crater
#

and how would i do that erm

quiet creek
#

repeat loop ends at until and then whatever you put after it and starts at repeat

#

so put it between line 108 and 110

fiery crater
#

so like that?

quiet creek
#

should be that

fiery crater
#

ok lemme try it

#

the error is gone so thats a good sign

#

yea nah the waves still happen

#

even though the break is in place

quiet creek
#

why would it stop

fiery crater
#

idk that was the point of having the break

quiet creek
#

arent you just printing?

fiery crater
#

nah it didnt print either

#

just printed the waves

quiet creek
#

when is the game supposed to end?

fiery crater
#

after 15 waves

quiet creek
#

might want to remake some of this script?

#

the repeat loop doesnt wouldnt stop the waves anyway

#

so the repeat loop is messed up and seemingly useless rn until whatever else is broken is fixed

fiery crater
#

after the 15 waves it says game over

hollow martenBOT
#

studio** You are now Level 9! **studio

quiet creek
fiery crater
#

yea after 15 waves it prints game ovr

#

but i wanted it to print game over once the "gameOverEvent" is triggered

quiet creek
#

what does gameOverEvent do?

fiery crater
#

game over event is triggered when the "Base" health is <= 0, and that causes the base to display "Base Destroyed"

#

thats the base

#

thats the script for the base

#

the base displays the current health

#

so like it would say "Base 500/500

#

smth like that

#

so my goal was, whenever the gameOverEvent is triggered, the wave system will stop

quiet creek
#

oh, why dont you make it turn gameOver to true or something to that manner?

fiery crater
#

thats the top of my main script

#

which is where my wave system is

fiery crater
quiet creek
# fiery crater

you could try connecting this directly to the event and stopping the waves maybe? im bout to go to sleep though

fiery crater
#

idk how to do that

quiet creek
#

i mean couldnt you just add the stop code inside of here?

fiery crater
#

that?

quiet creek
#

what code stops it at wave 15?

fiery crater
#

that

fiery crater
quiet creek
fiery crater
#

that i think

#

idk

#

the wave ends if there are no mobs on the map

#

see

quiet creek
#

no?

#

cause there's an if statement inside of the loop

#

that only checks for gameOver

#

maybe that's the issue? i cant really

#

tell

fiery crater
#

i can send the whole script if you want

quiet creek
#

i got to go to sleep

#

if you still are having the issue when i wake up

#

ill help

fiery crater
#

alright

quiet creek
#

gl g

fiery crater
#

thanks

subtle kestrel
hollow martenBOT
#

studio** You are now Level 1! **studio

subtle kestrel
#

you use a remote event to check when the game is over?

fiery crater
#

yea thats what the tutorial said to do

#

wait no

#

its a bindeable event

subtle kestrel
#

ohh

fiery crater
subtle kestrel
fiery crater
#

alright

#

base script

#

the top ones are for the wave system

#

ik its messy but

vocal herald
fiery crater
#

😭

subtle kestrel
# fiery crater

why is this part not in the loop

if wave == 1
then task.wait(wave + 15)
end
#

wave isn't defined in that part of the code so it doesn't know what to check for

fiery crater
#

man

#

idk

#

i made that part my self so its wrong

vocal herald
#

no wonder

fiery crater
#

there i fixed it

vocal herald
fiery crater
#

dont

subtle kestrel
#

it still won't know what wave is

subtle kestrel
#

make a wave variable at the top and change it whenever the wave changes

fiery crater
#

idk how to do that

#

idk how to script

#

i just use tutorials

subtle kestrel
#
local wave = 0
#

then when the wave is changed

#

you would make the variable = to the wave

#

that way other parts of the script know what wave it's on

#

instead of just the for loop

fiery crater
#

like there or

subtle kestrel
#

yeah that'll work

fiery crater
#

ok what next

subtle kestrel
#

maybe change it to like CurrentWave or something

#

so you don't get confused

fiery crater
#

change what to current wave

subtle kestrel
#

the variable you just made

fiery crater
#

that?

subtle kestrel
#

then in the

for wave=1,15 do
#

make currentWave = wave

fiery crater
#

is that good?

subtle kestrel
#

ye

fiery crater
#

okay

subtle kestrel
#

try testing it

fiery crater
#

yea i am rn

#

my map is pretty big so its gonna be a minute

subtle kestrel
#

alright lol

fiery crater
#

kthe base is about to die

#

nothing printed

subtle kestrel
#

what is it supposed to print

hollow martenBOT
#

studio** You are now Level 2! **studio

subtle kestrel
#

oh

#

"Game over"

fiery crater
#

yea

#

the next wave starts too

subtle kestrel
#

oh wait

#

lmfao

#

it's because the for loop is still running

#

so it never gets to the repeat

fiery crater
#

theres an end at the end oft he wave system

#

doesnt that end the for loop?

subtle kestrel
#

well yeah but that's after wave 15

#

the code is still running

#

task.spawn(function)

end)

#

put the for loop inside this

fiery crater
#

ik

#

that?

subtle kestrel
#

no the entire thing

fiery crater
#

oh

#

so like

#

the wave system too?

subtle kestrel
#

yes

fiery crater
#

oh okay

subtle kestrel
#

that's part of the loop

fiery crater
#

so that?

subtle kestrel
#

yes

#

but

#

task.spawn(function()

fiery crater
#

ok

#

so is it good now?

subtle kestrel
#

okay um

#

can you just copy and paste the script here I'll try to fix it for you

fiery crater
#

yes, sorry

subtle kestrel
#

np

fiery crater
#

local ServerStorage = game:GetService("ServerStorage")

local bindables = ServerStorage:WaitForChild("Bindables")
local gameOverEvent = bindables:WaitForChild("GameOver")

local base = require(script.Base)
local mob = require(script.Mob)
local tower = require(script.Tower)
local map = workspace.Grassland

local gameOver = false

base.Setup(map, 500)

gameOverEvent.Event:Connect(function()
gameOver = true
end)

local CurrentWave = 0

task.wait(10)

task.spawn(function()
for wave=1, 15 do
CurrentWave = wave
print("Wave", wave, "Starting")

if wave == 1 then workspace.Sound.Playing = true

end
if wave <= 1 then
    mob.Spawn("Zombie", 6, map)
elseif wave <= 2 then
    mob.Spawn("Zombie", 4, map)
    mob.Spawn("Noob", 2, map)    
    mob.Spawn("Zombie", 4, map)
elseif wave <= 3 then
    mob.Spawn("Zombie", 8, map)
    mob.Spawn("Noob", wave, map)    
elseif wave <= 4 then
    mob.Spawn("Zombie", 5, map)
    mob.Spawn("Noob", wave, map)    
    mob.Spawn("Zombie", 5, map)
elseif wave <= 5 then
    mob.Spawn("Zombie", 12, map)
    mob.Spawn("Noob", 5, map)    
elseif wave <= 6 then
    mob.Spawn("Zombie", 15, map)
    mob.Spawn("Mech", 1, map)
    mob.Spawn("Noob", 5, map)    
elseif wave <= 7 then
    mob.Spawn("Zombie", 5, map)
    mob.Spawn("Mech", 1, map)
    mob.Spawn("Noob", 10, map)    
    mob.Spawn("Zombie", 10, map)
elseif wave <= 8 then
    mob.Spawn("Zombie", 5, map)
    mob.Spawn("Noob", 5, map)    
    mob.Spawn("Zombie", 5, map)
    mob.Spawn("Mech", 1, map)
    mob.Spawn("Zombie", 5, map)
elseif wave <= 9 then
    mob.Spawn("Zombie", 10, map)
    mob.Spawn("Noob", 10, map)
    mob.Spawn("Mech", 3, map)
    mob.Spawn("Zombie", 10, map)
elseif wave <= 10 then
    mob.Spawn("Zombie", 15, map)
    mob.Spawn("Mech", 5, map)
    mob.Spawn("Noob", 10, map)
    mob.Spawn("Zombie", 15, map)
elseif wave <= 11 then
    mob.Spawn("Zombie", 15, map)
    mob.Spawn("Mech", 5, map)
    mob.Spawn("Noob", 10, map)
    mob.Spawn("Zombie", 20, map)
elseif wave <= 12 then
    mob.Spawn("Zombie", 15, map)
    mob.Spawn("Mech", 7, map)
    mob.Spawn("Noob", 15, map)
    mob.Spawn("Zombie", 20, map)
elseif wave <= 13 then
    mob.Spawn("Zombie", 10, map)
    mob.Spawn("Mech", 10, map)
    mob.Spawn("Noob", 15, map)
    mob.Spawn("Zombie", 10, map)
elseif wave <= 14 then
    mob.Spawn("Zombie", 10, map)
    mob.Spawn("Mech", 10, map)
    mob.Spawn("Noob", 20, map)
    mob.Spawn("Zombie", 10, map)
elseif wave <= 15 then
    mob.Spawn("Zombie", 2, map)
    mob.Spawn("Mech", 5, map)
    mob.Spawn("Zombie", 3, map)
    mob.Spawn("Noob", 5, map)
    mob.Spawn("Teddy",1, map)
    mob.Spawn("Noob", 10, map)

end        

end)

    task.wait(2)
    print("Wave", wave, "Ended")

task.wait(3)
end

repeat
task.wait(1)

if gameOver then
    print("Game Over")
    break
end

if wave >= 1
then task.wait(wave + 15)
    
end

until #workspace.Mobs:GetChildren() == 0 or gameOver

#

there u go

#

do you want me to send the other script too

#

for the base health

subtle kestrel
#

no that's okay

#

it's unrelated

fiery crater
#

kk

#

tysm for helping me out btw

subtle kestrel
#

np

#

what is this part supposed to do

#

why are you making it wait

fiery crater
#

well that was supposed to make it so that after the wave starts, it has to wait like, 15 seconds before it ends

#

in case you are afk at the beginning

subtle kestrel
#

I see

fiery crater
#

it wont be wave 15 by the time you get back

#

but if all mobs die, then the wave ends right then and therer

subtle kestrel
#
local ServerStorage = game:GetService("ServerStorage")

local bindables = ServerStorage:WaitForChild("Bindables")
local gameOverEvent = bindables:WaitForChild("GameOver")

local base = require(script.Base)
local mob = require(script.Mob)
local tower = require(script.Tower)
local map = workspace.Grassland

local gameOver = false

base.Setup(map, 500)

gameOverEvent.Event:Connect(function()
    gameOver = true
end)

local CurrentWave = 0

task.wait(10)

task.spawn(function()
    for wave=1, 15 do
        CurrentWave = wave
        print("Wave", wave, "Starting")

        if wave == 1 then workspace.Sound.Playing = true

        end
        if wave <= 1 then
            mob.Spawn("Zombie", 6, map)
        elseif wave <= 2 then
            mob.Spawn("Zombie", 4, map)
            mob.Spawn("Noob", 2, map)
            mob.Spawn("Zombie", 4, map)
        elseif wave <= 3 then
            mob.Spawn("Zombie", 8, map)
            mob.Spawn("Noob", wave, map)
        elseif wave <= 4 then
            mob.Spawn("Zombie", 5, map)
            mob.Spawn("Noob", wave, map)
            mob.Spawn("Zombie", 5, map)
        elseif wave <= 5 then
            mob.Spawn("Zombie", 12, map)
            mob.Spawn("Noob", 5, map)
        elseif wave <= 6 then
            mob.Spawn("Zombie", 15, map)
            mob.Spawn("Mech", 1, map)
            mob.Spawn("Noob", 5, map)
        elseif wave <= 7 then
            mob.Spawn("Zombie", 5, map)
            mob.Spawn("Mech", 1, map)
            mob.Spawn("Noob", 10, map)
            mob.Spawn("Zombie", 10, map)
        elseif wave <= 8 then
            mob.Spawn("Zombie", 5, map)
            mob.Spawn("Noob", 5, map)
            mob.Spawn("Zombie", 5, map)
            mob.Spawn("Mech", 1, map)
            mob.Spawn("Zombie", 5, map)
        elseif wave <= 9 then
            mob.Spawn("Zombie", 10, map)
            mob.Spawn("Noob", 10, map)
            mob.Spawn("Mech", 3, map)
            mob.Spawn("Zombie", 10, map)
        elseif wave <= 10 then
            mob.Spawn("Zombie", 15, map)
            mob.Spawn("Mech", 5, map)
            mob.Spawn("Noob", 10, map)
            mob.Spawn("Zombie", 15, map)
        elseif wave <= 11 then
            mob.Spawn("Zombie", 15, map)
            mob.Spawn("Mech", 5, map)
            mob.Spawn("Noob", 10, map)
            mob.Spawn("Zombie", 20, map)
        elseif wave <= 12 then
            mob.Spawn("Zombie", 15, map)
            mob.Spawn("Mech", 7, map)
            mob.Spawn("Noob", 15, map)
            mob.Spawn("Zombie", 20, map)
        elseif wave <= 13 then
            mob.Spawn("Zombie", 10, map)
            mob.Spawn("Mech", 10, map)
            mob.Spawn("Noob", 15, map)
            mob.Spawn("Zombie", 10, map)
        elseif wave <= 14 then
            mob.Spawn("Zombie", 10, map)
            mob.Spawn("Mech", 10, map)
            mob.Spawn("Noob", 20, map)
            mob.Spawn("Zombie", 10, map)
        elseif wave <= 15 then
            mob.Spawn("Zombie", 2, map)
            mob.Spawn("Mech", 5, map)
            mob.Spawn("Zombie", 3, map)
            mob.Spawn("Noob", 5, map)
            mob.Spawn("Teddy",1, map)
            mob.Spawn("Noob", 10, map)

        end
        
        if #workspace.Mobs:GetChildren() == 0 or gameOver then
            print("Game Over")
            break
        end
        
        if CurrentWave >= 1 then 
            task.wait(CurrentWave + 15)
        end
        print("Wave", CurrentWave, "Ended")
    end
end)
#

okay see if this works

fiery crater
#

ok ok

#

okay the waiting 15 seconds thing works

#

thats good

subtle kestrel
#

yup

#

moved it inside the for loop

fiery crater
#

can you add something to it rq while im running it

#

can you add a task.wait before the "print wave ended" thing right at the end

#

task.wait(3)

subtle kestrel
#

sure

fiery crater
#

right after here

#

ty

#

who let bro cook

#

i actually love youso much bro

#

holy

#

roberto

#

come here

subtle kestrel
#

awesome 🙏

#

glad I could help

fiery crater
#

im naming my first child after you

subtle kestrel
#

LOL

#

Good luck with your game brother 🙏

fiery crater
#

thanks man