The reason I’m confused is because you aren’t setting Wave to anything new except at the top of the for loop. There’s no reason for it to print “Wave 1 Wave 2” that I can see.
Could you show me the exact output?
The reason I’m confused is because you aren’t setting Wave to anything new except at the top of the for loop. There’s no reason for it to print “Wave 1 Wave 2” that I can see.
Could you show me the exact output?
I can’t really show you.
I already change it and it happened randomly.
I was frustrated when it happened.
I spend up to 3 hours trying to fix it and trying to find a solution, but all the time was wasted.
And I was confused why it happened.
I’m sorry for wasting your time.
I still haven’t learn how it works.
but I can instead image how it looked like
if it’s wave 2
Wave 2
Wave 1
if it’s wave 3
Wave 2
Wave 3
Wave 1
you basically get the point
it seems like it’s some kind of unorganized loop. I don’t know.
and again, sorry for wasting your time
Are each of these printed interdependently or grouped? It would help to see a screenshot if possible.
My only guess right now is that something is happening outside of this loop. That perhaps you have multiple of these loops running at once or something.
You aren’t accidentally calling the same loop are you? Is it inside a function that is called upon every wave? Your code looks fine but I would:
for Wave = 1, 10 do
-- Spawn initial enemies
Enemy.Spawn('ZombieBussinessman', Wave * 3, 0.2)
-- Additional enemy conditions
if Wave >= 2 and Wave <= 5 then
Enemy.Spawn('ZombieBussinessmanGunner', Wave * 1, 1)
end
if Wave >= 3 then
Enemy.Spawn("MedicZombie", 3, 0.1)
end
if Wave == 5 then
Boss.Spawn('BigZombieBoss', 3500)
end
-- Additional spawning for later waves
if Wave > 5 then
Enemy.Spawn('ZombieBussinessman', Wave * 3 / 2, 0.1)
Enemy.Spawn('ZombieBussinessmanGunner', Wave * 1 / 2, 0.2)
end
-- Wait until all enemies are defeated
repeat
task.wait(1)
until #workspace.Enemies:GetChildren() == 0
-- Fire events for wave completion
WaveEvent:Fire()
print("Wave: " .. Wave)
GiveIncome:Fire(Wave * 120 / #game.Players:GetPlayers())
wait(5)
NotificationEvent:FireAllClients("Wave " .. Wave .. " Completed", Wave)
end
P.S it’s spelled Business not Bussiness, but who really cares?
No, it’s not in a function. But it’s actually in an RemoteEvent called ‘StartButton’. The amount of enemies it spawns is alright; nothing wrong. But after the
repeat task.wait(1) until #workspace.Enemies:GetChildren() == 0
is where things start to get messy
and thank you for the correction
Sorry, but I can’t provide you a screenshot. It happened on a game that I was trying to finish as fast as I can, but the issue interrupt the process. Also it’s not in a function nor there isn’t anything outside the loop that is causing the issue
How often was this StartButton remote called?
Each time the event is called, a new instance of the connected function will execute. This will lead to duplicate instances of your for loop running. If this event is being called at the start of each round, this means that it’ll be on wave 2 on the first instance and wave 1 on the new instance. They sync up because of the matching delay they have, in which they wait until all enemies are gone.
I would place debug prints everywhere, before and after the suspected error.
Example:
StartButton.OnServerEvent:Connect(function()
print("StartButton triggered") -- Debugging line
end)
and or
local isWaveRunning = false
StartButton.OnServerEvent:Connect(function()
if not isWaveRunning then
isWaveRunning = true
print("Running")
for Wave = 1, 10 do
Enemy.Spawn('ZombieBussinessman', Wave * 3, 0.2)
print("Spawning ZombieBussinessman")
if Wave >= 2 and Wave <= 5 then
Enemy.Spawn('ZombieBussinessmanGunner', Wave * 1, 1)
print("Spawning ZombieBussinessmanGunner")
end
if Wave >= 3 then
Enemy.Spawn("MedicZombie", 3, 0.1)
print("Spawning MedicZombie")
end
if Wave == 5 then
Boss.Spawn('BigZombieBoss', 3500)
print("Spawning BigZombieBoss")
end
if Wave > 5 then
Enemy.Spawn('ZombieBussinessman', Wave * 3 / 2, 0.1)
Enemy.Spawn('ZombieBussinessmanGunner', Wave * 1 / 2, 0.2)
end
repeat task.wait(1) print("Waiting") until #workspace.Enemies:GetChildren() == 0
WaveEvent:Fire()
print("Wave: " .. Wave)
GiveIncome:Fire(Wave * 120 / #game.Players:GetPlayers())
wait(5)
NotificationEvent:FireAllClients("Wave " .. Wave .. " Completed", Wave)
end
isWaveRunning = false
else
print("Wave system is already running") -- Debugging line
end
end)
normally it’s called once. I don’t know why it does this
I’ve already done something like that, it prints multiple times after the
repeat wait(1) until