Why is my table thing not working

Hi guys,
im attempting to make a round system that checks if there is one guy left or 0 players left and the way i do that is with roblox teams and a table called local playing = {}
Just take a look at my script:

local playingTeam = game.Teams.Playing
local lobbyTeam = game.Teams.Lobby

local intermission = 10
local roundLength = math.huge

local inRound = game.ReplicatedStorage.InRound
local statusofzo = game.ReplicatedStorage.Status

local function round()
	while true do
		local requiredPlayers = 2

		repeat
			wait(1)
			statusofzo.Value = "At least ".. requiredPlayers.." players are needed to start a round"
		until #game.Players:GetChildren() >= requiredPlayers

		inRound.Value = false

		for i = intermission, 0, -1 do
			statusofzo.Value = "Game will start in "..i.." seconds"
			wait(1)
		end

		inRound.Value = true

		for i = roundLength, 0, -1 do
			local playing = {}


			for _, player in pairs(game.Players:GetChildren()) do
				if player.Team.Name == "Playing" then
					table.insert(playing, player.Name)
				end
			end

			print("Number of players in Playing team:", #playing)
			print("Contents of the playing table:", table.concat(playing, ", "))


			task.wait(0.1)

			if #playing == 0 then
				statusofzo.Value = "Everyone Has Died"
				wait(3)
				break
			end
			statusofzo.Value = #playing .. " players left"
			if #playing == 1 then
				statusofzo.Value = playing[1].." Has Won The Game!"

				for i, plr in pairs(game.Players:GetChildren()) do
					if playing[1] == plr.Name then
						plr.leaderstats.Wins.Value += 1
					end
				end

				wait(3)
				break
			end

			wait(1)
		end
		wait(3)
	end
end

spawn(round)

i have honestly no idea as to why it just wont work if you see it please let me know.
The one thing i think i know is that the player doesnt get added into the playing table.
Just to let you know, this is a part of the script and the rest of the script works perfectly fine

4 Likes

Does it show an error in the output? If so, please tell me it.

1 Like

There are no errors and thats the reason i cant fix the issue.

Oh damn i forgot to say something, what i meant with what doesnt work is that if the players are in it automatically says that there are no players

2 Likes

Does it still display players left: 0,1 ect?

2 Likes

My output looks like:
19:43:42.490 Contents of the playing table: - Server - RoundStuff:110
19:43:42.490 Player1 Lobby - Server - RoundStuff:19
19:43:42.491 Player2 Lobby - Server - RoundStuff:19
19:43:49.621 Player1 Playing - Server - RoundStuff:19

2 Likes

Alr, i’m not much of a coder but ill try my best. However, i must do something right now so ill help in a bit.
Thanks for your patience!

2 Likes

Hey!

After examining your script, I can see no issue with it.
If you could let me play your game. i will be able to see what works and doesn’t.

1 Like

Instead of checking the amount of players using a table each second of the round length loop, you could use a repeat until loop instead so that the code will yield until the amount of players left is one. This has worked for me, but just in case, keep a backup of your old code.

Here is a sample:

repeat
    wait(1)
until
    #game.Teams.Alive:GetPlayers() <= 1

Then, if you want the winner, you can use GetPlayers() to get the player on the alive team, since they will be the only one left.

Hope this helps!

Edit:
I have put <= 1 just in case the player leaves directly on the round ending.

1 Like

But i want it to end when there is no one alive too

1 Like

I’m not quite sure what you are trying to achieve.
Do you want the round to end when there is only one player left, or when there is none? If none, what do you want to happen after that?

1 Like

Holy damn ur thing worked i will test further

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.