Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How should I go about making a round system?

I've been trying to make some games that have a working round system in it. For the simple games that I tried to make, it worked perfectly. However, when I got into the more complex games with multiple different ways that the round could end, I didn't know what to use for a round system. When I say "what to use" I mean the use of while loops, for loops, changed events, etc. What I used for both of my games is a while wait() do loop (yes I know I shouldn't do that, its a habit that I'm trying to get rid of). The script looked something like this:

local RoundInProgress = game.ServerStorage.RoundInProgress
while wait() do
	if #game.Players:GetPlayers() < 2 then
		game.ReplicatedStorage.Status.Value = "Two or more players are required to start..."
	elseif #game.Players:GetPlayers() >= 2 and RoundInProgress.Value == false then
		RoundInProgress.Value = true
		-- Choose roles
		-- Choose map
		-- Teleport players
	else
		wait(1) --[[ I added this because there seemed to be an alternative somehow that 				 
    			       caused the loop to stop running. I don't know how that could be the case but 		 	 	 	 	 	 
 			       the addition of the else seemed to fix it.]]
	end

This seemed like a really good way to do a round system to me, until I tried to end the game when too many players left. When I did that, the players would teleport back and the round would never start again even though I got no errors. What I tried to do instead of just changing the variables is a force reset. I set a bool value to true and the script that was connected to the changed event would delete all the scripts and paste it back in. The problem with this was that every time a round started the map would destroy and the intermission would start again.

I'm not sure if the backstory was needed, but what I'm asking is what you guys would use to make a round system for your games. Thanks in advance.

2 comments

0

Did you make it so when a round ends it makes RoundInProgress.Value = false?

1

I would use a corortine.wrap function.

1 answer

✓ Accepted answer

Hi! As I'm currently making a round based game, I'll give you a brief rundown on my way of creating round-based games.

I create several functions, one for the intermission, one for choosing the round, and another for teleporting the players and such. However, for multiple gamemodes I usually use module scripts and require them and run a function within them.

while true do
	if #game:GetService("Players"):GetPlayers() < 10 then repeat wait(1) until #game:GetService("Players"):GetPlayers() >= 10 end

	--//We run some functions here and so on...
end

For rounds and stuff, we do

function roundStart()
	for i = 300,0,-1 do
		--Code here
	end
end

The code above is just a simple function, but what we'll do is insert a few conditionals so that every second we check the following:

  • If the timer is 0.
  • If the number of players is 1 or 0.
  • If some win condition is met
  • etc.

So we insert those, and we're done with the round start function!

local AlivePlayers = {}
local winCondition = false

function roundStart()
	for i = 300,0,-1 do
		if i == 0 then
 		
		elseif #AlivePlayers == 1 then

		elseif #AlivePlayers == 0 then

		elseif winCondition == true then

		end
	end
end

And finally, for stuff like last man standings, we can create loop that gets every since alive player in the game and check if they're dead and stuff, and if that's the case we remove them from the table.

for i,v in pairs(AlivePlayers) do
	if v then
		local Character = v.Character
		if Character and Character.Humanoid.Health > 0 then
		
		else
			table.remove(AlivePlayers,i)
		end
	else
		table.remove(AlivePlayers,i)
	end
end

In the code above we just run through the table to see if the player/character exists, if they're still alive, etc.

That's pretty much it.

1 comment

0

For the first piece of code, the if statement going into a repeat loop - you can do the same thing with a while statement. Great answer! while #game.Players:GetPlayers() < 10 do wait(1) end

This discussion is preserved as it was. New answers, comments, and votes are closed.