Tips to improve a pretty bad round system

Currently I’m making a game which is heavily based on rounds, similar to how Epic Mini Games works (game isn’t related to that).
Anyways I am completely aware that the way I made the round system is pretty bad & I’ve been thinking of ways to improve it.

To begin off, I have a script in ServerScriptService:

local ss = game.ServerStorage
local rp = game.ReplicatedStorage
local settings_ = require(script.Settings) --module of settings to be easily able to change stuff that might be imbalanced

function fireStatus(text)
	game.ReplicatedStorage.RoundStatus:FireAllClients(text) --text appears on player's screen about game info
end

function startRound()
	local randomizer = ss.ScriptReplications:GetChildren()
	local pickedGamemode = randomizer[math.random(1,#randomizer)]:Clone()
	pickedGamemode.Parent = game.ServerScriptService
	pickedGamemode.Disabled = false
end

function getAliveAndNotAfkPlayers() --returns a table full of players who have their hp above 0 and dont have afk mode on
	local t = {}
	for _,v in pairs(game.Players:GetChildren()) do
		if v.Afk.Value == false and v.Character.Humanoid.Health > 0 then
			table.insert(t,v)
		end
	end
	return t
end

rp.RoundStarted.CANCEL.Changed:Connect(function()
	wait(.1)
	for _,v in pairs(script.Parent:GetChildren()) do
		if v.Disabled then
			game.Debris:AddItem(v,2) --this is only here to prevent scripts from duplicating & taking up memory
			break
		end
	end
end)

spawn(function()
	while wait(settings_["StartTime"]) do
		if not rp.RoundStarted.Value and #game.Players:GetChildren() > 1 and #getAliveAndNotAfkPlayers() > 1 then
			wait(5)
			startRound()
		end
	end
end)

rp.RoundStarted.Timer.Changed:Connect(function()
	if rp.RoundStarted.Timer.Value <= 0 then
		for _,v in pairs(game.Players:GetChildren()) do
			if v.inGame.Value then
				v.Character.Humanoid:TakeDamage(100)
			end
		end
	end
end)

tl;dr: script clones a script from between specific modes & will not proceed until the round triggered the cancel bool to true and have the script deleted

For a bit of reference, these are how some stuff are set up:

image
These are the scripts in ServerStorage where a game mode will be chosen from.

image
These are the bools in ReplicatedStorage
what Timer does if it hits 0 the round automatically gets cancelled no matter what part it’s at, basically a force reset

What I’ve been thinking of improving:

  • Replacing the script cloning with using require() on module scripts.
  • Replacing spawn() with coroutines

So back to why I’m even posting this, is there any ways to improve my code?
Also if you don’t understand anything about it, please let me know and I’ll explain what it does.

The require() and replacing spawn() is a good idea. I also suggest looking into Attributes instead of using value instances. They are in Beta so if your game is already out don’t switch to them until they’re allowed in live Roblox servers.

I suggest having one long repeat script. I haven’t finished my round based game but here is what I have:

while true do
	-- Starts the intermission. Loops if there isn't enough players/restarts if playercount goes below minimum.
	StartIntermission()
	-- Gathers up the votes. Breaks up ties.
	GetVoteResults()
	-- Announces the most voted options.
	AnnounceVoteResults()
	-- Loads all selected details and blinds the players.
	BlindPlayers(true)
	LoadMap()
	LoadLighting()
	TeleportPlayers("Map")
	BlindPlayers(false)
	LoadMutation()
	LoadMode()
	-- Cleans up all details.
	BlindPlayers(true)
	ClearMap()
	ClearLighting()
	ClearMutation()
	TeleportPlayers("Lobby")
	BlindPlayers(false)
end

Your round script doesn’t look like it repeats the best way possible. A while true do loop guarantees it won’t stop unless there’s errors.

Hi there! I believe that this hyperlink might help. :slight_smile:
Round Set; Includes Weapon Spawners, Vehicle Spawners and much more