Is this code correct?
Also please rewrite it and explain whats wrong, if anythings wrong.
GameRunning = false
MinimumPlayers = 3
MinimumRoundTime = 5
game.Players.PlayerAdded:Connect(function(plr)
local children = workspace:GetChildren()
if #children >= MinimumPlayers then
print("Enough players are in the game | #".. #children)
GameStarting()
else
CheckForChildren()
print("Not enough children")
end
end)
function GameStarting()
local player = game:GetService("Players").LocalPlayer
local children = workspace:GetChildren()
local Intermission = Instance.new("IntValue")
Intermission.Parent = game.ReplicatedStorage
Intermission.Name = "IntermissionValue"
Intermission.Value = 15
game.Workspace.MainPart.Size = Vector3.new(158.225, 13.914, 113.146)
MapLoader()
task.wait()
while wait(0.01) do
player.PlayerGui.Timer.TimerText.Text = Intermission.Value
if Intermission.Value == 0 then
Intermission:Remove()
game.Workspace.MainPart.Size = Vector3.new(107.83, 13.914, 72.897)
player.PlayerGui.Timer.TimerText.Text = "One second..."
task.wait()
if #children <= 3 then
player.PlayerGui.Timer.TimerText.Text = "The players left! Please wait for more."
CheckForChildren()
else
player.PlayerGui.Timer.TimerText.Text = "Success"
task.wait()
player.PlayerGui.Timer.TimerText.Text = "Game in progress (?)"
player.PlayerGui.Timer.TimerText.Visible = true
MapLoader()
end
end
end
end
function CheckForChildren()
local player = game:GetService("Players").LocalPlayer
player.PlayerGui.Timer.TimerText.Text = "Not enough players! 3 players needed."
task.wait()
while wait(0.05) do
local children = workspace:GetChildren()
if #children >= MinimumPlayers then
GameStarting()
print("Fintilized, Enough children")
end
end
end
function MapLoader()
local Maps = game.ReplicatedStorage.Maps
Maps(Random.new(#1-2, #Maps))
if #2 then
local Map2Clone = Maps.Map2:Clone()
Map2Clone.Parent = game.Workspace
print("Map2 Selected")
UnhandleMatch()
end
if #1 then
local Map1Clone = Maps.Map1:Clone()
Map1Clone.Parent = game.Workspace
print("Map1 Selected")
UnhandleMatch()
end
end
function UnhandleMatch()
GameRunning = true
wait(game.ReplicatedStorage.RoundTime.Value)
GameRunning = false
print("Round Over")
RemateRoundTrigger()
end
function RemateRoundTrigger()
GameRunning = false
GameStarting()
print("Remating Round")
end
local children = workspace:GetChildren()
local plr = game:GetService("Players").LocalPlayer
while GameRunning == true do
if #children <= MinimumPlayers then
plr.PlayerGui.Timer.TimerText.Text = "The minimum amount of players are in the game. Going back to lobby."
wait(1)
if GameRunning == true then
CheckForChildren()
else
plr.PlayerGui.Timer.TimerText.Text = "Nevermind, Continue playing!"
wait(1.5)
plr.PlayerGui.Timer.TimerText.Text = "Game in progress (?)"
end
end
end
game.ReplicatedStorage.EndGameCommand.OnServerEvent:Connect(function()
RemateRoundTrigger()
end)
while wait(0.01) do
local RoundTime = game.ReplicatedStorage.RoundTime.Value
if RoundTime <= MinimumRoundTime then
RoundTime = MinimumRoundTime
end
end
game.ReplicatedStorage.StartGameCommand.OnServerEvent:Connect(function()
GameStarting()
print("Game is starting | AdminCommand fired for start ,.")
end)