Round gets played at the same time bu the amount of players in the game

so i have been working about a week on a round system and sometime randomly it plays the round the same amout of players i have check start when a player joins and i think that the problem and i need help fast because the game deadline is on feb 1st

script:

-- Varibles -- 

local RoundSerivce = {}

-- Strings --

local Waitime = "15"
local NEP = "Not Enough Players!"
local SI =  "Intermisson: 0"
local Status = " "

-- Ints --

local LeastPlayers = 2
local TimeWaiting = 1
local IntermissonTime = 5
local MaxAmoutGiving = 100
local Roatation = 20
local Round = 0

-- Bools --

local GivenPoints = false
local notfirstRound = false
local isfirstround = true
local RoundInProgess = false
local RoundHASStarted = false

-- Tables --

local Alive = {}
local Dead = {}
local Finshed = {}
-- Serivces --

local TeleportationPart = workspace:WaitForChild("Teleportation")
local ColourPickerSerivce = require(game:GetService("ReplicatedStorage").Serivces.ColourPickerSerivce)
local Players = game.Players
local RoundStarting = game.ReplicatedStorage.Remotes:FindFirstChild("RoundStarting")



-- Functions --

-- Sever --

function CalulateTickets(PlaceMent)
	Status = "NearIntermisson"
	local PointReward = MaxAmoutGiving /  (PlaceMent*2)
	local PlayerUserid = Finshed[PlaceMent]
	local Player = Players:GetPlayerByUserId(PlayerUserid)
	
	Player.leaderstats.Tickets.Value += math.ceil(PointReward)
	print(math.ceil(PointReward))
end


function Count()
	Status = "Intermisson"
	local Playerrs = 0
	for i,v in Players:GetPlayers() do
		Playerrs += 1
	end
	return Playerrs
end

function TPPlayers(Place)
	Status = "InProgess"

	for i,plr in pairs(Players:GetPlayers()) do
		plr.Character:PivotTo(Place.CFrame + Vector3.new(0,math.random(0,25)))
	end
end

function GiveTicketsToFailure()
	Status = "InProgess"
	for i,v in Dead do
		Players:GetPlayerByUserId(v).leaderstats.Tickets.Value += 1
	end
end

function InGame(Player: Player)
	Status = "InProgress"
	local DB = false
	local function BaseTouched(hit: Instance)
		if hit.Parent:FindFirstChild("Humanoid")   then
			if DB == true then return end
			DB = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			table.remove(Alive, table.find(Alive, plr.UserId))
			plr:RemoveTag("InGame")
			table.insert(Dead,plr.UserId)
			hit.Parent:PivotTo(game.Workspace.SpawnLocation.CFrame + Vector3.new(0,5,0))
			
			local number = 1
			for i = 1, #Alive do
				number += 1
			end
			print("There Is "..number.."People ALIVE THIS IS CHECKING FOR FINSH")

			if number == 0  then
				workspace.Baseplate:SetAttribute("OutOfPlayers",true)
				print("Appenly less 0 people but there is"..number)
			end
task.wait(1)
			DB = false
		end
	end
	local function FinshTouched(hit: Instance)
		if hit.Parent.Humanoid and DB == false then
			DB = true
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			if table.find(Alive,plr.UserId) then
			
				table.remove(Alive, table.find(Alive, plr.UserId))
				plr:RemoveTag("InGame")

				table.insert(Finshed,plr.UserId)
			local Awarder =require( game.ReplicatedStorage.Serivces.StatsAwarderSerivce)
			Awarder.Touched(hit)
			task.wait(.2)
			DB =false
			end
		end
	end
	workspace.GiverParts.Awrder.Touched:Connect(FinshTouched)
	workspace.Baseplate.Touched:Connect(BaseTouched)
end

local function Check2(tab)
	Status = "InProgess"
	local num = 0
	for _,v: Player in  pairs(game.Players:GetPlayers()) do
		if v:HasTag("InGame") then
		num += 1
		end
	end
	return num
end

local function RemoveUserid()
	Status = "Intermisson"
Finshed = {}
Dead = {}
Alive = {}

end

local function Check ()
	Status = "InProgess"
	if GivenPoints== true then
		return
	end
	for i = 1, #Finshed  do
		CalulateTickets(i)
	end	
end

local function AddPlayersToAliveTabel()
	Status = "InProgess"
	local AmoutPutIn = 0
	for i, plr in ipairs(game.Players:GetPlayers()) do
		table.insert(Alive,plr.UserId)
		AmoutPutIn += 1
		plr:AddTag("InGame")
	end
	return
end



function RoundSerivce.StartTime(Player: Player)
	task.wait(2)
	
	local Count2 = Count()
	if Count2 >= LeastPlayers then
		if Status == "InProgess"  and isfirstround == true  then return end
	isfirstround = false
		RoundHASStarted = true
		RoundStarting:FireAllClients(SI,2)
		RemoveUserid()
		while TimeWaiting ~= IntermissonTime do
			local NewCount = Count()
			if NewCount < LeastPlayers then
				RoundHASStarted = false
				RoundStarting:FireAllClients(NEP,"2")
				break
			end
			TimeWaiting += 1
			task.wait(1)
		end
		
		Round += 1
		print(Round)
		TimeWaiting = 1
		TPPlayers(TeleportationPart)
		AddPlayersToAliveTabel()
			workspace.Colours:SetAttribute("Round",Round)
		Status = "InProgess"
		InGame(Player)
		for i = 1,Roatation do
			if Check2(Alive) == 0 then
				GivenPoints = true
				print("G2")
				for i = 1, #Finshed  do
					CalulateTickets(i)
				end
				break
				end
			ColourPickerSerivce.Run()
			task.wait(3)
		end
		workspace.Baseplate:SetAttribute("OutOfPlayers",true)
	TPPlayers(workspace.SpawnLocation)
	Check()
	GivenPoints = false
		
print("Restarting Round")			
	else 
	print( "Not Enough Players!")
	end
end

function RoundSerivce.Stuff()
	if workspace.Baseplate:GetAttribute("OutOfPlayers") == true then
		print(Status)
		if Status == "Intermisson" then 
			workspace.Baseplate:SetAttribute("OutOfPlayers",false) 
			return
		end
		workspace.Baseplate:SetAttribute("OutOfPlayers",false) 
		Status = "Intermisson"
		RoundSerivce.StartTime()
		for i,v in game.Players:GetPlayers() do
			if v:HasTag("InGame") then
				v:RemoveTag("InGame")
			end
		end
	end
end

-- Client --

function RoundSerivce.ClentSide(Message,Type)
	local Player = game:GetService("Players").LocalPlayer
	if typeof(Type) == "number" then
		for i = IntermissonTime,1,-1 do
			Player.PlayerGui.Main.Countdown2.Text = Message..i
			task.wait(1)
		end
		Player.PlayerGui.Main.Countdown2.Text = "Round In Progress!"

	elseif typeof(Type) == "string" then
		Player.PlayerGui.Main.Countdown2.Text = Message

	
	end
end




-- Made By MrNobodyDev

return RoundSerivce

1 Like

what the hell does “round system plays the amount of players in the game” even mean

If there 5 players the round start 5 times at the same time

show me how ur using this module

ill try to point out all the mistakes i’ve spotted.

  1. why is waittime a string?
  2. Alive can be initialized as Players:GetPlayers()
  3. function Count Playerrs is just equal to #Players:GetPlayers(), iteration is not needed
  4. get rid of all pairs and use next, table or generalized iteration for i,v in table, they are both faster than pairs
  5. function InGame
local number = 1
for i = 1, #Alive do
	number += 1
end

what is this???
6. function Check2, num is just CollectionService:GetTagged("InGame")

and the main issue of this post
the reason why each player makes a round start, thats because RounService.StartTime takes in a player, and each call for each player starts a round.

im pretty sure in your main code you are calling this function for each player which starts round for each one

overall your code is a total mess, function names dont explain what the functions do.

scrap this whole module and start over

2 Likes

what type of script is this? is it a server script or a module?

Relax i think he speaks another language and is just trying to code a round game we should be kind

i havent said anything wrong? why are you coming at me for

no no im just saying the way you told him to scrap the entire script is kinda harsh

he needs to hear it if he wants to have a working round system by the deadline

alright i argee with you, so speaking of i think this script will do the job

local playerService = game:GetService("Players")
local MinPlayers = 10
local players = {}

for _, player in ipairs(playerService:GetPlayers()) do
	table.insert(players, player)
end

print("Number of players:", #players)
for _, player in ipairs(players) do
	print("Player Name:", player.Name)
end

if #players >= MinPlayers then
	print("Minimum player requirement met.")
else
	print("Minimum player requirement not met.")
end

had it laying around in my old scripts

also i advice for you to use the build in roblox ai to help you code

thats not even a round system? its just requirement check

yea its just like a starter pack, ya know to just give him some extra boost and stuff, sorry if this isnt enough

im still confused, because im trying my best to understand what the script you provided does

Alright after studying your script and looking for a very long time, im guessing its like a fighting round base system, so heres the script both local and serverservice script

serverservice script

local playerService = game:GetService("Players")
local MinPlayers = 0
local players = {}
local SetUpRound = game.ReplicatedStorage.SetUpRound
local StartingRound = game.ReplicatedStorage.StartingRound
local Alive = {}
local Dead = {}
local roundOn = false

local function Round()
	game.ReplicatedStorage.StartingRound.OnServerEvent:Connect(function()
		print("Starting Round")
		Alive = {}
		Dead = {}

		local randomSpawnPointsFolder = workspace:FindFirstChild("RandomSpawnPoints")

		if not randomSpawnPointsFolder then
			print("RandomSpawnPoints folder not found in Workspace.")
			return
		end

		local spawnPoints = randomSpawnPointsFolder:GetChildren()

		if #spawnPoints == 0 then
			print("No spawn points found in RandomSpawnPoints.")
			return
		end

		for _, player in ipairs(playerService:GetPlayers()) do
			if player.Character then
				local randomIndex = math.random(1, #spawnPoints)
				local selectedSpawn = spawnPoints[randomIndex]

				player.Character.HumanoidRootPart.CFrame = selectedSpawn.CFrame

				table.insert(Alive, player)

				local humanoid = player.Character:WaitForChild("Humanoid")
				humanoid.Died:Connect(function()
					for i, v in ipairs(Alive) do
						if v == player then
							table.remove(Alive, i)
							table.insert(Dead, player)
							print(player.Name .. " has died and is now in the Dead table.")
							break
						end
					end
				end)
			end

			player.CharacterAdded:Connect(function(character)
				local humanoid = character:WaitForChild("Humanoid")
				humanoid.Died:Connect(function()
					for i, alivePlayer in ipairs(Alive) do
						if alivePlayer == player then
							table.remove(Alive, i)
							table.insert(Dead, player)
							print(player.Name .. " has died and is now in the Dead table.")
							break
						end
					end
				end)
			end)
			if #Alive < 2 then
				for _, player in ipairs(Alive) do
					print("The Winner is: " .. player.Name)
					player:LoadCharacter()
					roundOn = false
				end
			end
		end
	end)
end

for _, player in ipairs(playerService:GetPlayers()) do
	table.insert(players, player)
end

while task.wait(1) do
	if #players >= MinPlayers and not roundOn then
		print("Max Players")
		task.wait(1)
		SetUpRound:FireAllClients()
		print("Fired Event")
	elseif not roundOn then
		print("Not Enough Players")
		return
	end
	Round()
	roundOn = true
	wait(5)
end

local script

local rep = game.ReplicatedStorage
local RoundText = script.Parent.TextLabel

rep.SetUpRound.OnClientEvent:Connect(function()
	print("Reseved Event")
	RoundText.Text = ""
	for i = 1 , 10 do
		RoundText.TextTransparency = RoundText.TextTransparency - 0.1
		wait(0.1)
	end
	for i = 1, 3 do
		RoundText.Text = "Starting in .." ..4 - i
		wait(1)
	end
	RoundText.Text = "Round In Progress"
	rep.StartingRound:FireServer()
end)
1 Like

1 Like

reason why i didnt even stay in the round because of the script checking if theres one alive player, and if there is then it restarts the round not before annoncing the winner in print

i hope this helps :slight_smile: anyways make sure to give me a tiny beany bit of credit

1 Like

Ok thanks for the script but i was planning on making my own one but you still jave some credit

1 Like