How To Make A Round-Based System

Will give it a try. Thanks for all the help!

For now, I did a rather Cheesy fix that works well enough. :slight_smile:
All I changed from the original script was the following, and, added a Spawn2 part to each map:

    function teleportPlayers()
    	local players = game.Players:GetPlayers()
    	for i,v in pairs(players) do
    		 if v.Team == game.Teams["Killer"] then
            	v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame
        	else
            	v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn2.CFrame
    		end
    	end
    end
1 Like

Hey, sorry for necroposting but I am using a modified version of this script for a FFA game and it isnā€™t working. What should I do?

-- TERMS

local teams = game:GetService("Teams")
local roundtime = -1
local inter = 20

while true do
	local skip = false
	print("Inter")
	while inter > 0 do
		local ps = game.Players:GetPlayers()
		if #ps >= 2 then
			inter = inter - 1
			wait(1)
		else
			while #ps < 2 do
				ps = game.Players:GetPlayers()
				print("Need More")
				wait(1)
			end
			skip = true
			inter = 0
		end
	end
	wait(1)
	if skip == false then
		sortTeams()
		print("round")
		while roundtime > 0 do
			wait(1)
		end
	end
	print("not enough")
	skip = false
	inter = 20
	roundtime = 200
end

function sortTeams()
	wait(3)
	local Players = game.Players:GetPlayers()
	local players = teams.Spectators:GetPlayers()

	-- Sort Remaining Players

	for i, player in ipairs (players) do
		player.Team = teams["Players"]
	end
	teleportPlayers()
	print("time")
	local localtimer = roundtime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		local kactive = false
		local activepeople = {}
		for _, s in pairs(teams.Players:GetPlayers()) do
			if s then
				table.insert(activepeople, s)
			end
		end
		if #activepeople < 2 then
			for _, k in pairs(teams.Players:GetPlayers()) do
				-- k.Cash.Value = k.Cash.Value + 50
			end
		end
			break
		if not kactive then
			for _, s in pairs(teams.Players:GetPlayers()) do
			end
			break
		end
	end

	-- Back To Lobby

	roundtime = 0
	wait(3)
	teleportBack()
	for i, player in ipairs (players) do
		player.Team = teams["Spectators"]
	end
end

function teleportPlayers()
	local players = game.Players:GetPlayers()
	for i,v in pairs(players) do
		game.Players:LoadCharacter()
	end
end

function teleportBack()
	local players = game.Players:GetPlayers()
	for i,v in pairs(players) do
		game.Players:LoadCharacter()
	end
end

You are all good, there is no issue here. I am happy to help anyone in need!

As for your issue make sure your while loop is under all of the functions, so they are considered as defined. With it above the functions it doesnā€™t actually know what sortTeams() is. Whenever you want to run a function, you need to make sure it is above the line of code that actually runs it.

I am sure if you even look in your output it might even say sortTeams() is nil or something similar. Hope this helps! If not please let me know and I can take a deeper look at your code.

Thank you, that helped fix the problem. I did what you suggested, but I started getting another error, " attempt to index nil with 'Spectators." What should I do to fix that? Thank you for your time.

-- TERMS

function sortTeams()
	wait(3)
	local Players = game.Players:GetPlayers()
	local players = teams.Spectators:GetPlayers()

	-- Sort Remaining Players

	for i, player in ipairs (players) do
		player.Team = teams["Players"]
	end
	teleportPlayers()
	print("time")
	local localtimer = roundtime
	while localtimer > 0 do
		wait(1)
		localtimer = localtimer - 1
		local kactive = false
		local activepeople = {}
		for _, s in pairs(teams.Players:GetPlayers()) do
			if s then
				table.insert(activepeople, s)
			end
		end
		if #activepeople < 1 then
			for _, k in pairs(teams.Players:GetPlayers()) do
				teleportBack()
			end
		end
	end
	if not kactive then
		for _, s in pairs(teams.Players:GetPlayers()) do
		end
	end
end

function teleportPlayers()
	local players = game.Players:GetPlayers()
	for i,v in pairs(players) do
		game.Players:LoadCharacter()
	end
end

function teleportBack()
	local players = game.Players:GetPlayers()
	for i,v in pairs(players) do
		game.Players:LoadCharacter()
	end
end

local teams = game:GetService("Teams")
local roundtime = -1
local inter = 20

while true do
	local skip = false
	print("Inter")
	while inter > 0 do
		local ps = game.Players:GetPlayers()
		if #ps >= 1 then
			inter = inter - 1
			wait(1)
		else
			while #ps < 1 do
				ps = game.Players:GetPlayers()
				print("Need More")
				wait(1)
			end
			skip = true
			inter = 0
		end
	end
	wait(1)
	if skip == false then
		sortTeams()
		print("round")
		while roundtime > 0 do
			wait(1)
		end
	end
	print("not enough")
	skip = false
	inter = 20
	roundtime = 200
end

	-- Back To Lobby

	roundtime = 0
	wait(3)
	teleportBack()
	for i, player in ipairs (players) do
		player.Team = teams["Spectators"]
	end
1 Like

Sorry for the late reply. Probably from this little portion here, make sure you are defining things before you try to run your code. Scripts read from top to bottom and if you are trying to run something it hasnā€™t gotten to yet it will error.

Also is this necessary? It might break your code since players technically isnā€™t defined for it. Make sure to look through your code and see if you can spot anymore errors. Iā€™m sure you could have solved these yourself, although if you have any more problems you need help with please let me know!

1 Like

while true do
while true do
while true do
end
end
end

Can you do a car tutorial next?

1 Like

Where is the leaderstats @? LOL

Leaderstats? This is a round-based system tutorial, not a datastore tutorial. I am confused as to why I would need leaderstats, but if you could explain to me why it is necessary that would be appreciated.

In the script the player gets cash. Donā€™t you need a leaderstats for that?

Sorry for the incredibly late reply, but as I said before this is a round based system tutorial not a datastore tutorial. I donā€™t even have any cash variable written in the script. If people wanted to add a feature for giving players cash after a round I would expect them to do that, since that isnā€™t the purpose of this tutorial.

I donā€™t see why you would need to have a leaderstats in a round-based system tutorialā€¦

Usually it will give the player cash after the player has won the round! BUT I wasnt 99.9% sure on the script.

1 Like