Hey, I am trying to make the round in my game end when all players die but with the code I have used it never runs the countdown again and the entire module script seems to break or freeze?!
I have tried searching the forum but I can’t find a solution
Module Script
function roundModule.CountdownGame(status, clock)
roundInfo.GameStatus.Value = status
roundInfo.Timer.Value = clock
for i = clock, 1, -1 do
if #roundInfo.InGame:GetChildren() <= 0 then
break
else
task.wait(1)
roundInfo.Timer.Value = roundInfo.Timer.Value - 1
end
end
end
Game Loop Script
local function StartGame()
PlayerModule.teleportAllPlayers(workspace.Rounds.GameTeleport)
RoundModule.CountdownGame("Game", GameTime)
end
while task.wait() do
Intermission()
StartGame()
end
local function Intermission()
RoundModule.LobbySelection()
--task.wait(2)
for i, PlayerMarker in pairs(RoundInfo.InGame:GetChildren()) do
local Marker = PlayerMarker:Clone()
Marker.Parent = game.ReplicatedStorage.RoundInfo.Survivors
end
PlayerModule.respawnAllPlayers()
task.wait(2)
RoundModule.SurvivorsScreen()
RoundInfo.Banger:ClearAllChildren()
gamePlayers:ClearAllChildren()
while #LobbyPlayers:GetChildren() < 1 do
task.wait(1)
end
RoundModule.Countdown("Intermission", IntermissionTime)
--task.wait(5)
RoundModule.Voting("Voting")
task.spawn(VotingCount, "Voting", VoteTime)
VotingModule.VoteBegin(VoteTime) -- vote time
RoundModule.BangerSelection("Start")
task.spawn(VotingCount, "Banger Selection", 5)
task.wait(5)
RoundModule.BangerSelection("Remove")
RoundModule.LoadingScreen(true)
task.wait(2)
RoundModule.LoadingScreen(false)
end
local roundModule = {}
local events = game.ReplicatedStorage:WaitForChild("Events")
local roundInfo = game.ReplicatedStorage:WaitForChild("RoundInfo")
local PlayersNeededToStart = script.Parent:GetAttribute("PlayersNeeded")
local Replicated = game:GetService("ReplicatedStorage")
local RNG = math.random()
Entire module script
local roundModule = {}
local events = game.ReplicatedStorage:WaitForChild("Events")
local roundInfo = game.ReplicatedStorage:WaitForChild("RoundInfo")
local PlayersNeededToStart = script.Parent:GetAttribute("PlayersNeeded")
local Replicated = game:GetService("ReplicatedStorage")
local RNG = math.random()
function roundModule.LobbySelection()
workspace.LoadedLobby:ClearAllChildren()
local mapstorage = Replicated.Lobbys:GetChildren()
local mapnumber = math.random(1, #mapstorage)
local lobbynew = mapstorage[mapnumber]:Clone()
lobbynew.Parent = workspace.LoadedLobby
workspace:WaitForChild("PlayerList").CFrame = lobbynew.PlayerListLocation.CFrame
end
function roundModule.Countdown(status, clock)
roundInfo.GameStatus.Value = status
roundInfo.Timer.Value = clock
for i = clock, 1, -1 do
if clock ~= 0 then
task.wait(1)
roundInfo.Timer.Value = roundInfo.Timer.Value - 1
end
end
end
function roundModule.Voting(status)
roundInfo.GameStatus.Value = status
end
function roundModule.SurvivorsScreen()
local Players = {}
local Banger
for i, v in pairs(roundInfo.Survivors:GetChildren()) do
local Player = game:GetService("Players"):FindFirstChild(v.Name)
table.insert(Players, Player)
--print(Player.UserId)
--print(Player.Name)
--print(typeof(v), "Module")
end
for i, v in pairs(roundInfo.Banger:GetChildren()) do
Banger = game:GetService("Players"):FindFirstChild(v.Name)
end
events:WaitForChild("Survivors"):FireAllClients(Players, Banger)
--print("send")
end
function roundModule.LoadingScreen(Toggle)
game:GetService("ReplicatedStorage").Events.LoadingScreen:FireAllClients(Toggle)
end
function roundModule.BangerSelection(State)
local Event = game:GetService("ReplicatedStorage").Events:WaitForChild("Banger")
if State == "Remove" then
Event:FireAllClients(false)
else
local Players = game:GetService("Players")
local choosenPlr:Instance
if #(Players:GetPlayers()) >= PlayersNeededToStart then
choosenPlr = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]
end
local Character = choosenPlr.Character or choosenPlr.CharacterAdded:Wait()
-- Set Up Identifier
local Tag = Instance.new("BoolValue")
Tag.Name = "IsBanger"
Tag.Value = true
Tag.Parent = Character
local Highlight = Instance.new("Highlight")
Highlight.DepthMode = Enum.HighlightDepthMode.Occluded
Highlight.FillTransparency = 0.75
Highlight.OutlineTransparency = 0.85
--Highlight.Parent = Character
local Marker = Instance.new("StringValue")
Marker.Name = choosenPlr.Name
Marker.Parent = roundInfo.Banger
Event:FireAllClients(true, choosenPlr)
end
end
return roundModule
Given that the for loop counts the clock down until 1 is reached, it won’t reach 0.
I’d also recommend just doing roundInfo.Timer.Value = i.
As for the script breaking, I don’t see why it would break but it might be because it gets stuck in one of the functions. I would recommend debugging it either by putting a lot of print statements in your script or by using the debugger (I don’t use the debugger since idk how it works and I don’t think it would be useful in this situation).
Found out the problem was not in fact the break, but was when a player dies their marker in the INGame folder is destroyed and was not recreated and added to the lobby folder so the GameLogic script hanging was actually doing its job by not starting until there was players in the lobby folder. I moved the timer into the script instead of the module script, I haven’t tested it inside the module script but Im not planning to as it works now.