Hello, I am making a killer game and want to make it so that the round restarts when the killer kills all the victims. I have a line of code that checks if the number of players in the survivor teams is zero. However, when i tested it in a local server no matter the amount of players in the victim team the round restarts.
Gameloop:
--Varibles
local EveryobodyDead = game.ReplicatedStorage.Values["Everyones dead"]
local Players = game:GetService("Players")
local RoundManager = require(script:WaitForChild("RoundManager"))
local replicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
local Status = replicatedStorage.Values.Status
local Intermission = 25
local RoundTime = 300
local HidingTime = 30
local PlayersToStart = 2
local Knife = game.ServerStorage.Knife:Clone()
local VictimTeam = game.Teams.Victims:GetPlayers()
local KillerTeam = Teams.Killer
--Functions
function ChooseKiller(players)
return players[math.random(1, #players)]
end
while wait(1) do
for i = Intermission, 0, -1 do
Status.Value = "Next Round Starts in: " ..i -- Intermission Timer
wait(1)
end
local victims = game.Players:GetPlayers()
local killer = ChooseKiller(victims)
local Lobby = Teams.Lobby
Status.Value = "The killer is... "
wait(2)
Status.Value = killer.Name.."!"
wait(3)
for i, v in pairs(Players:GetChildren()) do
if v:IsA("Player") then
v.Team = game.Teams.Victims
end
if v:IsA(killer) then
killer.Team = KillerTeam
end
end
killer.Character:FindFirstChild("Humanoid").WalkSpeed = 24
RoundManager:TeleportVictims()
for i = 30, 0, -1 do
Status.Value = "The killer comes in "..i.." seconds!"
wait(1)
end
Knife.Parent = killer.Backpack
RoundManager:TeleportKiller(killer)
for i = RoundTime, 0, -1 do
Status.Value = "Time left until the round ends: "..i
wait(1)
if #VictimTeam <= 0 then
Status.Value = "The Killer has Killed Everyone!"
wait(5)
break
end
end
Knife.Parent = game.ServerStorage
RoundManager:CleanupRound()
for i, v in pairs(Players:GetChildren()) do
if v:IsA("Player") then
v.Team = game.Teams.Lobby
end
end
end
Module Script:
-- Services
local Players = game.Players:GetChildren()
local ServerStorage = game:GetService("ServerStorage")
local Teams = game:GetService("Teams")
-- Varibles
local Maps = ServerStorage.Maps:GetChildren()
local SelectMap = Maps[math.random(1, #Maps)]
local TeleportsRound = SelectMap.TeleportRound:GetChildren()
local KillerTeleport = SelectMap.KillerTeleport:FindFirstChild("Telepart")
local LobbySpawn = workspace.Lobby.LobbyTele
local Killer = Teams.Killer:GetPlayers()
local Victims = Teams.Victims:GetPlayers()
-- Module
local RoundManager = {}
function RoundManager:TeleportVictims()
SelectMap.Parent = workspace
for _, Victim in pairs(game.Teams.Victims:GetPlayers()) do
local character = Victim.Character or Victim.CharacterAdded:Wait()
character.HumanoidRootPart.CFrame = TeleportsRound[math.random(1, #TeleportsRound)].CFrame
end
end
function RoundManager:TeleportKiller(killer)
local Killercharacter = killer.Character or killer.CharacterAdded:Wait()
Killercharacter.HumanoidRootPart.CFrame = KillerTeleport.CFrame
print(killer)
end
function RoundManager:CleanupRound()
SelectMap.Parent = ServerStorage.Maps
for _, player in pairs(game.Players:GetChildren()) do
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Health = 0
humanoid.WalkSpeed = 16
end
end
return RoundManager