Hello, Everyone. This is my first project after 2 years of being inactive in ROBLOX. I’m trying to make a zombie-shooting type game and is still learning to code(Basic).
function System:StartWave() is where I am putting the code. I wanna make it so that if “one” player is still alive in that round and other players are in the lobby, the round will keep going and will teleport the players from the lobby to the round(Once all enemies/zombies are dead, though I already made that script).
I am also having problem with the indicator, if all the players have died and was sent back to the lobby, the round would reset.
I accept any kinds of help and tips, criticizing also. And Thank you.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local SystemFolder = game.Workspace.System
local ZombieFolder = game.Workspace.Zombies
local CountdownFolder = SystemFolder.Countdown
local ZombieModel = ServerStorage.Models.Zombie
local System = {}
System.Time = {
"Hours",
"Minutes",
"Seconds",
}
function System:LoadObjects()
local roundValue = Instance.new("NumberValue")
roundValue.Name = "amtRound"
roundValue.Parent = SystemFolder
roundValue.Value = 1
local defZombiesValue = Instance.new("NumberValue")
defZombiesValue.Name = "defZombiesValue"
defZombiesValue.Parent = SystemFolder
defZombiesValue.Value = 10
local zombiesValue = Instance.new("NumberValue")
zombiesValue.Name = "amtZombies"
zombiesValue.Parent = SystemFolder
zombiesValue.Value = 10
local zombiesMultiplier = Instance.new("NumberValue")
zombiesMultiplier.Name = "zombieMultiplier"
zombiesMultiplier.Parent = SystemFolder
zombiesMultiplier.Value = 5
local zombiesThisRound = Instance.new("NumberValue")
zombiesThisRound.Name = "zombiesThisRound"
zombiesThisRound.Parent = SystemFolder
zombiesThisRound.Value = 0
local IsRoundCountdown = Instance.new("BoolValue")
IsRoundCountdown.Name = "IsRoundCountdown"
IsRoundCountdown.Parent = SystemFolder
IsRoundCountdown.Value = 5
for i, v in pairs(System.Time) do
local timeType = Instance.new("IntValue")
timeType.Name = v
timeType.Parent = CountdownFolder
end
end
function System:StartWave()
local roundValue = SystemFolder.amtRound
local zombiesValue = SystemFolder.amtZombies
local defZombiesValue = SystemFolder.defZombiesValue
local zombiesMultiplier = SystemFolder.zombieMultiplier
local zombiesThisRound = SystemFolder.zombiesThisRound
for _, pl in pairs(Players:GetPlayers()) do
if pl.InLobby.Value == true then
local character = pl.Character
if character then
local humRootPart = character.HumanoidRootPart
if humRootPart then
humRootPart.CFrame = workspace.PlayerSpawn.CFrame
end
end
pl.InLobby = false
print("Teleporting Player(s).")
---Once all players died the round must restart
---Unless "one" player is still alive the round will keep going and teleport all players
---If that "one" player is dead it will restart
end
end
zombiesThisRound.Value = defZombiesValue.Value + (roundValue.Value - 1) * zombiesMultiplier.Value
for i = 1, zombiesThisRound.Value do
task.wait(.3)
local clonedZombie = ZombieModel:Clone()
clonedZombie.Name = "Zombie" .. i
clonedZombie.Parent = ZombieFolder
local humanoidRootPart = clonedZombie:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
humanoidRootPart.CFrame = workspace.ZombieSpawner.CFrame + Vector3.new(0, 10, 1)
end
zombiesValue.Value = #ZombieFolder:GetChildren()
end
end
function System:Count()
local zombiesValue = SystemFolder.amtZombies
for i in pairs(ZombieFolder:GetChildren()) do
zombiesValue.Value = #ZombieFolder:GetChildren()
end
if #ZombieFolder:GetChildren() == 0 then
zombiesValue.Value = #ZombieFolder:GetChildren()
end
end
function System:Countdown(timeLeft, timer, IsRound)
local hoursValue = CountdownFolder.Hours
local minsValue = CountdownFolder.Minutes
local secondsValue = CountdownFolder.Seconds
local countdownZombValue = SystemFolder.IsRoundCountdown
--System:Countdown(10, TimerText)
for i = timeLeft, 0, -1 do
timeLeft = i
countdownZombValue.Value = true
local hours = math.floor(timeLeft / 3600)
local minutes = math.floor((timeLeft % 3600) / 60)
local seconds = math.floor(timeLeft % 60)
hoursValue.Value = hours
minsValue.Value = minutes
secondsValue.Value = seconds
task.wait(1)
if IsRound == true and timeLeft == 0 then
countdownZombValue.Value = false
System:StartWave()
end
end
end
return System