Hello I am making a weather controller game. It's like Deathrun 2 combined with Natural Disaster Survival. I have already made the whole game script but it glitches. What happens is when there are no players alive, the game message will say "The weather controller has won" then "Awarding points to every surviving player" then it says "The weather controller has resetted/left" but it's not suppose to say it. I tried finding the bug but I couldn't find it. Can you please help me? Here's the whole script (I'm sorry if it is so long):
time = game.Workspace.Time
maps = game.ServerStorage.Maps:GetChildren()
gm = game.Workspace.GameMessage
---
function checkPlayers()
local playercount = 0
local players = game.Players:GetChildren()
if game.Workspace.RoundRunning.Value == true then
for i = 1, #players do
if players[i].Character ~= nil then
if players[i].Team.Value == "Players" then
playercount = playercount + 1
end
end
end
end
if playercount == 0 then
time.Value = 0
game.Workspace.RoundRunning.Value = false
gm.Value = "The weather controller has won!"
wait(2)
gm.Value = "Awarding 30 points to the weather controller (+15 Weather Controller Benefits)"
for n, v in pairs (game.Players:GetChildren()) do
if v.Team.Value == "Controller" then
if v.PlayerStats.ControllerBenefits.Value == true then
v.PlayerStats.Points.Value = v.PlayerStats.Points.Value + 45
v.PlayerStats.ControllerWins.Value = v.PlayerStats.ControllerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
elseif v.PlayerStats.ControllerBenefits.Value == false then
v.PlayerStats.Points.Value = v.PlayerStats.Points.Value + 30
v.PlayerStats.ControllerWins.Value = v.PlayerStats.ControllerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
end
elseif v.Team.Value == "Players" then
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
end
end
end
end
---
function checkController()
local ctrlcount = 0
local plyrs = game.Players:GetChildren()
if game.Workspace.RoundRunning.Value == true then
for i = 1, #plyrs do
if plyrs[i].Character ~= nil then
if plyrs[i].Team.Value == "Controller" then
ctrlcount = ctrlcount + 1
end
end
end
end
if ctrlcount == 0 then
time.Value = 0
game.Workspace.RoundRunning.Value = false
gm.Value = "The weather controller ressested/left"
wait(2)
gm.Value = "Awarding 15 points to every surviving player (+15 Player Benefits)"
for n, v in pairs (game.Players:GetChildren()) do
if v.Team.Value == "Players" then
if v.PlayerStats.PlayerBenefits.Value == true then
v.PlayerStats.Points.Value = v.PlayerStats.Points.Value + 30
v.PlayerStats.PlayerWins.Value = v.PlayerStats.PlayerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
elseif v.PlayerStats.PlayerBenefits.Value == false then
v.PlayerStats.Points.value = v.PlayerStats.Points.Value + 15
v.PlayerStats.PlayerWins.Value = v.PlayerStats.PlayerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
end
elseif v.Team.Value == "Controller" then
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
end
end
end
end
---
function checkTime()
if game.Workspace.RoundRunning.Value == true then
if time.Value == 1 then
time.Value = 0
game.Workspace.RoundRunning.Value = false
gm.Value = "Time's up! The weather controller did not kill the players in time"
wait(2)
gm.Value = "Awarding 15 points to every surviving player (+15 Player Benefits)"
for n, v in pairs (game.Players:GetChildren()) do
if v.Team.Value == "Players" then
if v.PlayerStats.PlayerBenefits.Value == true then
v.PlayerStats.Points.Value = v.PlayerStats.Points.Value + 30
v.PlayerStats.PlayerWins.Value = v.PlayerStats.PlayerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
elseif v.PlayerStats.PlayerBenefits == false then
v.PlayerStats.Points.Value = v.PlayerStats.Points.Value + 15
v.PlayerStats.PlayerWins.Value = v.PlayerStats.PlayerWins.Value + 1
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed.Value + 1
end
elseif v.Team.Value == "Controller" then
v.PlayerStats.RoundsPlayed.Value = v.PlayerStats.RoundsPlayed + 1
end
end
end
end
end
---
while wait() do
while game.Players.NumPlayers < 0 do
gm.Value = "Atleast 2 players are needed to play"
wait()
end
for i = 5, 1, -1 do
gm.Value = "Intermission: " ..i
wait(1)
end
wait(1)
gm.Value = "Choosing a map"
wait(1)
choosingmap = math.random(1, #maps)
roundmap = maps[choosingmap]
wait(1)
gm.Value = "Map Chosen: " ..roundmap.Name.. " by " ..roundmap.Creator.Value
game.Workspace.CurrentMap.Value = roundmap.Name
wait(1)
gm.Value = "Loading map... Please wait"
roundmapClone = roundmap:Clone()
roundmapClone.Parent = game.Workspace
roundmapClone.Name = "RoundMap"
wait(1)
gm.Value = "Teleporting players"
wait(1)
for n, v in pairs (game.Players:GetChildren()) do
if v.Character.Torso ~= nil then
v.Character.Torso.CFrame = roundmapClone.PlayerSpawn.CFrame + Vector3.new(math.random(-5, 5), 0, math.random(-5, 5))
v.Character.Humanoid.WalkSpeed = 0
v.Team.Value = "Players"
end
end
wait(1)
gm.Value = "Choosing weather controller"
local players = game.Players:GetChildren()
wc = players[math.random(1, #players)]
wc.Team.Value = "Controller"
wc.Character.Torso.CFrame = roundmapClone.ControllerSpawn.CFrame + Vector3.new(math.random(-1, 1), 0, math.random(-1, 1))
wc.Character.Head.Transparency = 1
wc.Character.Humanoid.WalkSpeed = 0
wait(1)
gm.Value = "The weather controller is " ..wc.Name
wait(1)
gm.Value = "Starting round"
game.Workspace.RoundRunning.Value = true
for n, v in pairs (game.Players:GetChildren()) do
if v.Team.Value == "Players" then
v.Character.Humanoid.WalkSpeed = 16
elseif v.Team.Value == "Controller" then
v.Character.Humanoid.WalkSpeed = 24
end
end
wait(1)
time.Value = 180
while time.Value >= 1 do
time.Value = time.Value - 1
gm.Value = "Game ends in: " ..time.Value
checkPlayers()
checkController()
checkTime()
wait(1)
end
wait(2)
for n, v in pairs (game.Players:GetChildren()) do
v.Character.Torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(math.random(-5, 5), 0, math.random(-5, 5))
v.Character.Head.Transparency = 0
v.Character.Humanoid.WalkSpeed = 16
v.Team.Value = "Lobby"
end
roundmapClone:destroy()
end

2 comments
If you put it in code block, it would be easier to figure out what is wrong!
Oh sorry I'm new here. I just did it.