I have a script, it works fine the first wave, but when you get to the second wave, it spawns in groups of five on top of each other and lags the game like crazy! Here is the script
repeat wait(1) if script.WaveHas.Value == 0 then if script.Parent.WaveCount.Value == 2 then script.WaveHas.Value = 1 local AmountOfWaves = 15 -- How many waves do you want? Put them here local TimePerWave = 5 -- How long you want to wait per wave local function SpawnWave() local Bot = game.ReplicatedStorage.Alien:Clone() Bot.Parent = workspace Bot:MoveTo(Vector3.new(math.random(-254,254), 5, math.random(44,255))) end for CurrentWave = 1, AmountOfWaves do SpawnWave() wait(TimePerWave) end script.Parent.TimeLeft.Value = 120 wait(120) script.Parent.WaveCount.Value = 3 print("set to wave 3") end end until script.Parent.WaveCount.Value > 2
Please help!!! Thank you!!! PS. each wave is in a different script, but are all the same (other than variables such as WaveCount)
The Problem:
I can tell, 15 groups are being spawned due to your 'for' sequence
Script:
Not tested I hope this works, reply if it does/doesn't
repeat wait(1) AmountOfAliens = 2 -- Amount of aliens for a wave, change it in the scripts if you want if script.WaveHas.Value == 0 then if script.Parent.WaveCount.Value == 2 then script.WaveHas.Value = 1 local AmountOfWaves = 15 -- How many waves do you want? Put them here local TimePerWave = 5 -- How long you want to wait per wave local function SpawnWave() local Bot = game.ReplicatedStorage.Alien:Clone() Bot.Parent = workspace Bot:MoveTo(Vector3.new(math.random(-254,254), 5, math.random(44,255))) end for CurrentWave = 1, AmountOfAliens do SpawnWave() wait(TimePerWave) end script.Parent.TimeLeft.Value = 120 wait(120) script.Parent.WaveCount.Value = 3 print("set to wave 3") end end until script.Parent.WaveCount.Value > 2