local roundtime = 30
local unitsperound = {
Wave1 = 5,
Wave2 = 15,
Wave3 = 50,
Wave4 = 150
}
local Wave = 0
local enemiesLeft = 0
local isinround = false
local enemiesfolder = game.Workspace.Enemies:GetChildren()
function EndRound()
isinround = false
game.Workspace.Enemies:ClearAllChildren()
end
function BeginRound()
Wave = Wave + 1
isinround = true
if Wave == 1 then
for I = 1, 5 do
Spawnunit()
end
elseif Wave == 2 then
for I = 1, 15 do
Spawnunit()
end
elseif Wave == 3 then
for I = 1, 50 do
Spawnunit()
end
elseif Wave == 4 then
for I = 1, 105 do
Spawnunit()
end
end
end
function Spawnunit()
local cloned = game.ReplicatedStorage.NPC:Clone()
cloned.Parent = game.Workspace.Enemies
end
function lose()
--
wait(2)
script:Destroy()
print("lost") -- just realised this should be one line above
end
function win()
--
wait(2)
script:Destroy()
print("won")
end
function ResetWave()
enemiesLeft = 0
end
function Getenemies()
for i, v in pairs(enemiesfolder) do
enemiesLeft = enemiesLeft + i
print(i)
end
end
local RemotEvents = game.ReplicatedStorage.RemoteEvents
local Begingameevent = RemotEvents.Begin
local loseevent = RemotEvents.Lose
local wineevent = RemotEvents.Win
local spawnunitevent = RemotEvents.SpawnUnit
local startroundevent = RemotEvents.StartRound
local endroundevent = RemotEvents.End
local updevent = RemotEvents.UPD
local Firstroundbegan = false
-- makeing the actual game part
Begingameevent.OnServerEvent:Connect(function()
BeginRound()
startroundevent:FireAllClients(Wave)
Firstroundbegan = true
end)
local intermissiontime = 5
wait(5)
Firstroundbegan = true
repeat
print("Repeating")
if Firstroundbegan == true then
print("Roundtimer Has began")
BeginRound()
startroundevent:FireAllClients(Wave)
wait(roundtime)
for i, V in pairs(enemiesfolder) do
if i == 0 then
ResetWave()
EndRound()
endroundevent:FireAllClients(Wave, "Round Has Completed")
else
lose()
loseevent:FireAllClients("Game Lost")
print("game lost")
end
end
end
until
Firstroundbegan == true
Yes i know i created an array and didnt use it and i have functions im not using and it doesnt really work.
its been changed a lot. it had a lot of For loops before i changed it a bit and had a function called RequestGetEnemies(). I also know that Else if arguments are not very advanced.