What's the best way to fix this round loop?

Sorry. The methods of the script was throwing me off a little. And no, I can’t help there either.

Do you have a discord account?

Yes, direct message me if you want it.

have you verified #tables.playersInRound’s value? i.e. print it.

yes, it has nothing to do with that. It has to do with the fact the status gets glitchy after the round ends. I was asking for a better loop that would work.

I’ll record a video right now if you really want to see it.

You should read more properly before posting.

dont be a prickly pear about it all im doing is making sure

if it successfully prints then when you check the condition, break the loop

this also doesn’t make sense. all that does is wrap the enclosing function. so whatever is after it, is being executed after wrapping takes place. If there is anything after it anyway.

You don’t get my point. And yes I tried all of those. But if I do the break loop it will restart the game but won’t declare the winner. Do you have discord, why don’t you dm me and ill explain this whole thing once again.

I know that. Like i said its not proper. I’m looking for a better way. This way works but is buggy. Buggy as in the status bar I have glitches for a bit when the game ends. (obviously cuz its running the loop until the end). I’m looking for a better loop to this. I tired many stuff like:

while while #tables.playersInRound >= 2 do`` or ``if #tables.playersInRound < 2 then break But none of those things will declare the winner. Only reset the game.

Ok here is the function in the module that check what the winner is:

 CheckWinner = function(parent, gameChosenClone)
        if #tables.playersInRound > 1 then
            while #tables.playersInRound >= 2 do
                if gameChosenClone.Name ~= "SimonSays" then
                    parent.Value = "Game in progress"
                end
                wait()
                if #tables.playersInRound == 1 then
                    local player = tables.playersInRound[1]
                    print("The Winner is: " .. player.Name)
                    parent.Value = player.Name .. " has won this round!"
                    wait(5)
                elseif #tables.playersInRound == 0 then
                    print("There was not a single winner.")
                    parent.Value = "No one won this round"
                    wait(5)
                end
            end
        end
    end;

why do you have:

while #tables.playersInRound >= 2 do

when you check:

 if #tables.playersInRound == 1 then

and

 elseif #tables.playersInRound == 0 then

when the while loop won’t even run once <2 players exist.

what? I don’t think you get how my system works. Ok here is the whole Module: Take a look if you like: https://pastebin.com/6YHazPdS

Edit: If you want the script that runs all these functions please let me know.

            while true do
                if gameChosenClone.Name ~= "SimonSays" then
                    parent.Value = "Game in progress"
                end
                wait()
                if #tables.playersInRound == 1 then
                    local player = tables.playersInRound[1]
                    print("The Winner is: " .. player.Name)
                    parent.Value = player.Name .. " has won this round!"
                    wait(5)
                    break
                elseif #tables.playersInRound == 0 then
                    print("There was not a single winner.")
                    parent.Value = "No one won this round"
                    wait(5)
                    break
                end
            end

would this not work?

this wouldn’t work for the other two gamemodes classic and randomizer.

Wait hold on lemme try once more and double check.

Edit: It does work but it breaks my afk system. Like now whenever one person is not afk and the rest are, it would not skip the winners like it used to. I may have to do big changes. Hold on let me configure some things and I’ll get back to you if I need help.

So how would I fix the issue with the afk? Its not working as it used to now.

Edit:

so my goal here is that whenever there is only one player in the server not afk before the game starts, it will give a little warning and restart the game

AddPlayer = function(player, teleports, i, status)
		if player:IsA("Player") then
			if not otherFunctions:IsPlayerAFK(player) then
				print("player is not afk")
				print(player)
				table.insert(tables.playersInRound, player) -- add all players to table
				connections[player.Name] = player.Character.Humanoid.Died:Connect(function()
					table.remove(tables.playersInRound, table.find(tables.playersInRound, player))
				end)
				player.Character:MoveTo(teleports[i].Position)
				if #tables.playersInRound == 1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					
				end
			elseif otherFunctions:IsPlayerAFK(player) then
				print("player is afk")
				table.insert(tables.AfkPlayers, player)
			end	
		end
	end;

I edited in this function here idk how to return to the beginning after this

if #tables.playersInRound == 1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					return
				end

happens.

I tired putting return but it did nothing but continue on. (I think its because this is a module function, not in an actual script. How do I fix this.) @Juicy_Fruit

you’re just checking if playersinround == 1 but that is == the win condition

I think you need to add an extension to check if the maximumplayers - #playersafk ~= 1 or something (this means: 9 players max, 8 players afk, if 1 player not afk and everyone else is afk then don’t do this)

could you give an example to this?

Like just give a brief example on how it may look like I just want to see. I don’t really understand what your trying to say. @Juicy_Fruit

local CurrentMaxPlayers = 0


--in game loop update the variable to current players as an integer value

if #tables.playersInRound == 1 and CurrentMaxPlayers-#AfkPlayers==1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					return
				end

Ok so I took your example of yours and here’s what I got:

AddPlayer = function(player, teleports, i, status)
		if player:IsA("Player") then
			if not otherFunctions:IsPlayerAFK(player) then
				print("player is not afk")
				print(player)
				table.insert(tables.playersInRound, player) -- add all players to table
				connections[player.Name] = player.Character.Humanoid.Died:Connect(function()
					table.remove(tables.playersInRound, table.find(tables.playersInRound, player))
				end)
				local currentMaxPlayers = game.Players.NumPlayers
				if #tables.playersInRound == 1 or currentMaxPlayers - tables.AfkPlayers == 1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					tables.playersInRound = {}
					return
				end
				player.Character:MoveTo(teleports[i].Position)
			elseif otherFunctions:IsPlayerAFK(player) then
				print("player is afk")
				table.insert(tables.AfkPlayers, player)
			end	
		end
	end;local currentMaxPlayers = game.Players.NumPlayers
				if #tables.playersInRound == 1 or currentMaxPlayers - tables.AfkPlayers == 1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					tables.playersInRound = {}
					return
				end

For some reason tho once all but 1 person is afk it will still display the next time even tho there are at least 2 people not afk. How would reset this?

Here is the part where it has this btw:

local currentMaxPlayers = game.Players.NumPlayers
				if #tables.playersInRound == 1 or currentMaxPlayers - tables.AfkPlayers == 1 then
					status.Value = "Other players are afk. Tell them to turn off their afk!"
					wait(3)
					tables.playersInRound = {}
					return
				end

I tired resetting the tables but it didn’t work. Although I don’t think that would work since I already have a function anyways after that resets the table.

should be #tables.AfkPlayers

you don’t need a local in each thing u can just put a local at the top and then have all ur functions modify and read from there