Hello, I am running into a bug I am unsure how to fix. I have this script below, in which when the zombiesAlive value is 0 the next round will proceed and +1 is added to the wave value.
The issue is, if i have multiple zombies that a player kills at the same time, for example with a grenade, the function seems to repeat the amount of zombies that were killed, thus increasing the wave more than once.
For example, If the player is on round 1, and kills the last 3 zombies at the same time, the wave will then proceed to round 4 instead of round 2.
I am assuming this is because it gets connected to “0” multiple times? Here is the code:
zombiesAlive:GetPropertyChangedSignal("Value"):Connect(function()
if #collectionservice:GetTagged("Alive") == 0 then
return
end
if zombiesAlive.Value == 0 then
workspace.RoundEnd:Play()
wait(10.8)
workspace.Roundstart:Play()
for i, Player in pairs(game.Players:GetPlayers()) do
if not Player:GetAttribute("Ready") then
continue
end
local Character = Player.Character
if Character == nil or Character.PrimaryPart == nil then
Player:LoadCharacter()
continue
end
if Player.Team == game.Teams.Players then
--print "ignore active players"
else
print "new players"
local Backpack = Player:WaitForChild("Backpack")
if wave.Value >= 10 then
Player.leaderstats.Money.Value = 5000
else
Player.leaderstats.Money.Value = 500 * wave.Value
end
collectionservice:AddTag(Player, "Alive")
Character:WaitForChild("Torso").CFrame = workspace.Map:FindFirstChildOfClass("Model").Spawn.CFrame * CFrame.new(0,2,0)
Player.Team = game.Teams.Players
Character.SetCamera.Enabled = true
Player.PlayerGui.MainGui.MenuBackground.Visible = false
Player.PlayerGui.MainGui.MainBackground.Visible = false
print (Player.PlayerGui.MainGui.MenuBackground.Visible)
print (Player.PlayerGui.MainGui.MainBackground.Visible)
Player.PlayerGui.Cash.Enabled = true
Player.PlayerGui["Health Gui"].Enabled = true
-----------------------------------------------OLD LOADHAND HANDLE-----------------------------------------------
--////////////////////////////////////////////////////////////////
Character.WeaponHandler.Primary.Value = Player.CurrentGun.Value
Character.WeaponHandler.CurrentWeapon.Value = "Primary"
--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-----------------------------------------------OLD LOADHAND HANDLE-----------------------------------------------
if #collectionservice:GetTagged("Alive") > 1 then
workspace.Map.Normal.QuickRevive.Part.ProximityPrompt.Enabled = true
workspace.Map.Normal.QuickRevive.Part.ProximityPrompt.ObjectText = "$1500"
workspace.Map.Normal.QuickRevive.Part.ProximityPrompt.Price.Value = 1500
else
workspace.Map.Normal.QuickRevive.Part.ProximityPrompt.ObjectText = "$500"
workspace.Map.Normal.QuickRevive.Part.ProximityPrompt.Price.Value = 500
end
for i, Object in pairs(Backpack:GetChildren()) do
if Object.Name == Player.CurrentGun.Value then
Player.Character.Humanoid:EquipTool(Object)
end
end
end
end
wave.Value += 1
zombieCount.Value = 0.000058 * (wave.Value)^3 + 0.074032 * (wave.Value)^2 + 0.718119 * (wave.Value) + 14.738699
zombiesAlive.Value =0.000058 * (wave.Value)^3 + 0.074032 * (wave.Value)^2 + 0.718119 * (wave.Value) + 14.738699
if wave.Value > 9 then
game.ServerStorage.Zombie.Humanoid.Health = game.ServerStorage.Zombie.Humanoid.Health * 1.1
else
game.ServerStorage.Zombie.Humanoid.Health = game.ServerStorage.Zombie.Humanoid.Health + 100
end
if game.ReplicatedStorage.Values.DogRound.Value == true then --Doggies
game.ReplicatedStorage.Values.DogsLeft.Value = 4 * #collectionservice:GetTagged("Alive")
zombieCount.Value = 4 * #collectionservice:GetTagged("Alive")
zombiesAlive.Value = 4 * #collectionservice:GetTagged("Alive")
else
zombieCount.Value = 0.000058 * (wave.Value)^3 + 0.074032 * (wave.Value)^2 + 0.718119 * (wave.Value) + 14.738699 --COD zombies formula
zombiesAlive.Value =0.000058 * (wave.Value)^3 + 0.074032 * (wave.Value)^2 + 0.718119 * (wave.Value) + 14.738699
end
end
end)