I have this tower defense game and I wanna add wave skipping. I found this tutorial but it seemed super sloppy but I cant really do any better. I kinda want it to be like in TDS where it appears and most people have to accept but I havent scripting in like a year so Im really rusty. Any help is appreciated, thanks!
2 Likes
This should be pretty close to what you need
local wave = 1
local waveTime = 60
local betweenWavesTime = 20
local enemies = enemiesFolder:GetChildren()
local skipWave = false
skipWaveButton.Activated:Connect(function()
skipWave = true
end)
while true do
if #enemies > 0 and waveTime > 0 then
task.wait(1)
waveTime -= 1
else
while betweenWavesTime > 0 do
task.wait(1)
betweenWavesTime -= 1
end
end
if betweenWavesTime <= 0 or skipWave then
if skipWave and #enemies > 0 then
for i = 1, #enemies do
enemiesFolder[i]:Destroy()
end
end
wave += 1
waveTime = 60
betweenWavesTime = 20
skipWave = false
end
end
2 Likes
But that destroys all enemies. Im just thinking it gives the reward, spawns in the next set of mobs
1 Like
Then you could just take out the for loop that destroys all the mobs, as well as the other checks for #enemies and it should still be fine.
Edit: just leave the initial check
if waveTime > 0 and #enemies > 0
Or else the cooldown for the next wave will start before the first wave is completed lol
Unless you want to keep the enemies and spawn more still, ofc
1 Like