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

Round ends automatically... Help?

Edit:

		alive = {}
		
		for i,v in pairs(game.Players:GetPlayers()) do
			if v:FindFirstChild("InGame") then
				v.InGame.Value = true
				table.insert(alive, i)
			end
		end
		
		
		for i = 1,120 do 
        	if #alive == 1 then
            	for i,v in pairs(game.Players:GetPlayers()) do
                	if v:FindFirstChild("PlayerGui") then
                   		v.PlayerGui.timer.Frame.timer.Text = (alive[1] .. "Has won!")
                    end
                end

                break
        	end
        	if #alive == 0 then
            	break
        	end
			for _, v in pairs(game.Players:GetPlayers()) do
    			if v.InGame.Value == false then
        			for i, z in ipairs(alive) do
            			if (not z) or v == z then
                			table.remove(alive, i)
            			end
       			 	end 
   	 			end
			end
			wait(1)
		end 
	

2 answers

✓ Accepted answer

Your problem is actually in the first block of code you posted:

Change table.insert(alive, i) to table.insert(alive, v).

You're inserting the index of the player in the GetPlayers table, instead of the Player themselves.

Edit 2: Change

for i,v in pairs(game.Players:GetPlayers()) do
	if v.InGame.Value == false then
		table.remove(alive, i)
	end
end

To

for _, v in pairs(game.Players:GetPlayers()) do
	if v.InGame.Value == false then
		for i, z in ipairs(alive) do
			if (not z) or v == z then
				table.remove(alive, i)
			end
		end	
	end
end

13 comments

0

Now the round doesn't end. Would I use table.remove(alive, i) to remove the player; or??

0

That should be working fine. Have it print #alive to the output to check what it's at when people die.

0

I get the error "Wrong number of arguments to insert"

0

Woops, I'm sorry. I answered incorrectly. I edited my answer, try it now.

0

Found another bug. Should work now!

0

The round still ends right when it starts. The InGame value does not bug, if you're wondering. In your second edit did you mean (alive, v)? because you wrote (alive, i).

0

Is it because I'm still using 'if #alive <1 then' ?

0

The chunk of code under Edit 2 should work as it is.

0

Change the 'if #alive' bits to how you had them in the question.

0

It still ends when it starts. I can edit it to show you what I have so far.

0

Nevermind, I forgot to add a wait, but now it doesn't end... Is there even a way to fix this? I'm using what you're saying. I will edit my question and put what I have so far.

0

Can't the table.insert(alive, i) in the first loop to table.insert(alive, v)

0

It works PERFECT now!!! Thanks so much! I know I might of been a little stupid not knowing how to fix it and you didn't have to take this much time to fix it, but thank you so much! I have asked around 100 people and you actually helped fix it!! thanks so much.

Try this in line 02 if #alive < 1 then

2 comments

1

I clearly stated that that didn't work. I tried it before, and it just ended the round when 1 player died; even if there were 3+ players in the server.

0

message me on roblox so i can help more

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