Hi, I’m creating a zombie wave game and I am nearly finished writing out all the code, but when I test the game the script is ignoring most of the if statement’s tasks. The game will start with the intermission timer but then it will keep repeating that instead of saying wave 1. Here is the script:
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local gv = RS.Values.gv
local DiedValue = RS.Values.DV
local wave = RS.Values.Wave
local ZombiesRemaining = RS.Values.ZombiesRemaning
local TimeToWait = RS.Values.TimeToWait.Value
local IGT = RS.Values.InGameTime
local Restart = true
local KillAllZombies = RS.Values.KillAllZombies
local GIP1 = RS.Values.gameInProgress1
local playersInRound = {}
local playersDisconnected = {}
local playerDies = {}
local lobbyTime = 20
local isOverrided = false
local inRound = false
Players.PlayerRemoving:Connect(function(Player)
table.insert(playersDisconnected, Player)
if table.find(playersInRound, Player) then
table.remove(playersInRound, table.find(playersInRound, Player))
if #playersInRound == 0 then
print("Everyone has died!")
inRound = false
end
end
end)
local function doRound()
inRound = true
playersInRound = {}
playersDisconnected = {}
for _, Player in ipairs(Players:GetPlayers()) do
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HRP = Character:WaitForChild("HumanoidRootPart")
--HRP.CFrame = CFrame.new(0, 0, 0) --good spawn location
if GIP1.Value == 1 then
table.insert(playersInRound, Player)
Humanoid.Died:Connect(function()
table.insert(playersDisconnected, Player.Name)
table.remove(playersInRound, table.find(playersInRound, Player))
if #playersInRound == 0 then
print("Everyone has died!")
inRound = false
task.wait(1)
end
end)
end
end
end
function Loop()
while true do
wave.Value = 1
Restart = false
for i = lobbyTime, 0, -1 do
gv.Value = i
wait(1)
end
local value = RS.Values.MainGame
GIP1.Value = 1
doRound()
local function MyCoroutine()
while true do
task.wait(1)
value.Value -= 1
IGT.Value = value.Value
print("Timer:", value.Value)
end
end
local RunMC = coroutine.wrap(MyCoroutine)
RunMC()
if ZombiesRemaining.Value > 0 then
repeat
task.wait()
until
ZombiesRemaining.Value <= 0
end
if ZombiesRemaining.Value <= 0 then
wave.Value = wave.Value + 1
value.Value = 120
ZombiesRemaining.Value = 10 + wave.Value
if TimeToWait ~= 0.5 then -- If it hasn't reached 0.5 yet
TimeToWait = TimeToWait - 0.1 -- Decrease the current TimeToWait by 0.1
else
TimeToWait = 0.5
end
if inRound == false then
Restart = true
DiedValue.Value = "Game Over"
KillAllZombies.Value = true
GIP1.Value = 0
task.wait(3)
break
end
if IGT == 0 then
Restart = true
DiedValue.Value = "Game Over"
KillAllZombies.Value = true
GIP1.Value = 0
task.wait(3)
break
end
end
end
end
if Restart == true then
Loop()
end
task.spawn(function()
while task.wait() do
if not inRound then
doRound()
end
end
end)
Video of what’s happening:
Script Ignores Assignements.wmv (5.1 MB)