Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Round ends automatically... Help?

Asked by 10 years ago

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

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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
0
Now the round doesn't end. Would I use table.remove(alive, i) to remove the player; or?? systematicaddict 295 — 10y
0
That should be working fine. Have it print #alive to the output to check what it's at when people die. adark 5487 — 10y
0
I get the error "Wrong number of arguments to insert" systematicaddict 295 — 10y
0
Woops, I'm sorry. I answered incorrectly. I edited my answer, try it now. adark 5487 — 10y
View all comments (9 more)
0
Found another bug. Should work now! adark 5487 — 10y
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). systematicaddict 295 — 10y
0
Is it because I'm still using 'if #alive <1 then' ? systematicaddict 295 — 10y
0
The chunk of code under Edit 2 should work as it is. adark 5487 — 10y
0
Change the 'if #alive' bits to how you had them in the question. adark 5487 — 10y
0
It still ends when it starts. I can edit it to show you what I have so far. systematicaddict 295 — 10y
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. systematicaddict 295 — 10y
0
Can't the table.insert(alive, i) in the first loop to table.insert(alive, v) adark 5487 — 10y
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. systematicaddict 295 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

Try this in line 02 if #alive < 1 then

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. systematicaddict 295 — 10y
0
message me on roblox so i can help more littledamian55 0 — 10y

Answer this question