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

[UNSOLVED] Why is this loop not working?

Asked by 9 years ago

So the script is supposed to detect how many players are on a team and if the amount of players on a team changes or not. So if there wasn't enough people on each time (the minimum is 1 player), it would print a message. But if the teams suddenly got enough players, it would begin the game, and vice versa.

The script worked before, and now it's not working, and I have no idea why. Everything is defined. Can someone please help me?

Here's the script:

local Ready = script:WaitForChild("Ready")

local team = game.Teams;

function getPlayers(teamColor) -- team color is easier than name
    local found = { };
    for _,v in pairs(game.Players:GetPlayers()) do
        if v.TeamColor == teamColor then
            table.insert(found, v)
        end
    end
    return #found
end

while wait() do
    print('Starting game')
    wait(5)
    while wait() do
        local greenNum = getPlayers(BrickColor.new('Bright green'))
        local redNum = getPlayers(BrickColor.new('Bright red'))
        if Ready.Value == false then
            if greenNum > 0 and redNum > 0 then
            Ready.Value = true
            else 
            print('Nope')
            end
        end
    end
    if Ready.Value == true then
    print('Starting game...')
    end
end
1
Oh hey look, my code. Anyways.. I don't understand why you have two while loops.. unless if you added an else statement on line 30 that used the break statement. But you don't, so help me understand. Goulstem 8144 — 9y
0
The second loop is for it to refresh. The first one is for the rest of the code. CoolJohnnyboy 121 — 9y
1
It's never going to go past the second loop because it's endless, mate. that's why i'm saying make a break statement inside an else statement after line 30. Goulstem 8144 — 9y
0
I tried adding a break, still didn't work CoolJohnnyboy 121 — 9y
0
not sure what you need, but how about while (Ready.Value == false) do? FutureWebsiteOwner 270 — 9y

Answer this question