I am making a basic round system and I just wanted to know if there was a way to make it better.
Here is the code:
game.Players.PlayerAdded:connect(function(player) gameStatus = Instance.new("IntValue", player) gameStatus.Name = "gameStatus" gameStatus.Value = 0 end) function playerNotifications(playerNotifications) for i, v in pairs(game.Players:GetChildren()) do local gameInterface = v.PlayerGui:FindFirstChild('GameInterface') if gameInterface then gameInterface.TopBar.Background.Notifications.Text = playerNotifications end end end function timeText(timeText) for i, v in pairs(game.Players:GetChildren()) do local gameInterface = v.PlayerGui:FindFirstChild('GameInterface') if gameInterface then gameInterface.TopBar.Time.Text = timeText end end end function gameIntermission() if game.Players.NumPlayers >= 1 then for Timer = 20, 0, -1 do wait(1) playerNotifications('Intermission! (You might want to get ready.)') if Timer > 9 then timeText('0:'.. Timer) else timeText('0:0'.. Timer) end end end end function mapSelect() if game.Players.NumPlayers >= 1 then local maps = {"Neonplate", "Plastic Paradise"} playerNotifications("Selecting the map!") wait(5) local map = game.ReplicatedStorage.Maps[maps[math.random(1, #maps)]] mapClone = map:Clone() mapClone.Parent = game.Workspace local mapname = map.Name playerNotifications("Map selected!") wait(2) playerNotifications("Map Chosen: ".. mapname) gameStatus.Value = 1 end end function teleportPlayers() if game.Players.NumPlayers >= 1 and gameStatus.Value == 1 then local mapSpawns = mapClone.Spawns:GetChildren() for i, v in ipairs(game.Players:GetChildren()) do v.Character.Torso.CFrame = mapSpawns[math.random(#mapSpawns)].CFrame + Vector3.new(0, i * 5, 0) end end end function cloneSwords() local swordClone = game.ReplicatedStorage.Weapons.Sword:Clone() swordClone.Parent = game.Players.LocalPlayer.Backpack end function removeSpawns() local mapSpawns = mapClone.Spawns mapSpawns:Destroy() end function roundStart() if game.Players.NumPlayers >= 1 then playerNotifications('The round has begun!') wait(0.5) for Timer = 15, 0, -1 do wait(1) playerNotifications('Time left:') if Timer > 9 then timeText('0:'.. Timer) else timeText('0:0'.. Timer) end end end end function roundEnd() for i, v in pairs(game.Players:GetPlayers()) do local name = v.Name playerNotifications("Time's up!") wait(2) playerNotifications("The winner was: ".. name) wait(2) playerNotifications("New round!") local humanoid = v.Character:FindFirstChild("Humanoid") if humanoid and gameStatus.Value == 1 then humanoid.Health = 0 end gameStatus.Value = 0 end end function mapDestroy() if mapClone.Parent == game.Workspace then mapClone:Destroy() end end while wait() do gameIntermission() wait(1) mapSelect() wait(1) teleportPlayers() wait(1) removeSpawns() cloneSwords() roundStart() wait(1) roundEnd() wait(1) mapDestroy() end