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

[SOLVED] Why is This Game Round/Match Script Not Working Correctly?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I know this is not the first time I have asked for help on this code, bu the other times, I was not including the rest of the code.

The code basically runs the game.

The code runs fine, except for the part where it determines if there are enough players or not on the teams.

If there is at least one person on both teams, the script will run fine. However, if there are not enough people on either team, the script will say that there is not enough people for the game to begin, and even if the teams reach at least one person on each team, the script will still say that there is not enough to begin the game.

Can someone please help me?

Here's the script

local Playing = script:WaitForChild("Playing")
local Time = script:WaitForChild("Time")
local Down = script:WaitForChild("Count")
local Start = script:WaitForChild("StartUp")
local msg = Instance.new("Message")
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
    if Start.Value == true and Playing.Value == false then
        Start.Value = false
        msg.Parent = game.Workspace
        msg.Text = "Starting the game up..."
        wait(4)
        msg.Text = "Choose a team!"
        wait(3)
        local player = game.Players:getPlayers() 
        for i = 1, #player do 
            player[i].Character.Humanoid.Health = 0
        end
        wait(27)
        while wait() do -------- I suppose the error is between this line
            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
                    msg.Text = "Still waiting for there to be at least person on each team..."
                end
            end
            break
        end ----and this line
        if Ready.Value == true then
            Ready.Value = false
            for i = 1, #player do
                local player = game.Players:getPlayers() 
                if player[i].TeamColor == BrickColor.new("White") then
                    player[i].TeamColor = BrickColor.new("Bright red")
                end
            end
            msg.Text = "The game starts now!"
            wait(2.5)
            msg:remove()
            for i = 1, #player do 
                player[i].Character.Humanoid.Health = 0
            end
            Playing.Value = true
            Down.Value = true
            Time.Value = 150
        end
    end
    if Playing.Value == true then
        if getPlayers(BrickColor.new('Bright green')) == 0 or Time.Value == 0 then
            Function() ----This isn't the actual function. This is actually a different function I did not include in the script
            wait(4)
            Function2() ----This isn't the actual function. This is actually a different function I did not include in the script
        end
    end
end
0
Please point out where the problem is by giving the line that it starts on. parkderp1 105 — 9y
0
I did. I pointed the area of suspected error with green lines saying that this is where I suspect the error to be CoolJohnnyboy 121 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Righty ho, this is alvin for proof I can tell you that I was in Remove Price Floors Now.

Righty ho, try this


local Playing = script:WaitForChild("Playing") local Time = script:WaitForChild("Time") local Down = script:WaitForChild("Count") local Start = script:WaitForChild("StartUp") local msg = Instance.new("Message") 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 if Start.Value == true and Playing.Value == false then Start.Value = false msg.Parent = game.Workspace msg.Text = "Starting the game up..." wait(4) msg.Text = "Choose a team!" wait(3) local player = game.Players:getPlayers() for i = 1, #player do player[i].Character.Humanoid.Health = 0 end wait(27) while wait() do -------- I suppose the error is between this line 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 break else msg.Text = "Still waiting for there to be at least person on each team..." end end end ----and this line if Ready.Value == true then Ready.Value = false for i = 1, #player do local player = game.Players:getPlayers() if player[i].TeamColor == BrickColor.new("White") then player[i].TeamColor = BrickColor.new("Bright red") end end msg.Text = "The game starts now!" wait(2.5) msg:remove() for i = 1, #player do player[i].Character.Humanoid.Health = 0 end Playing.Value = true Down.Value = true Time.Value = 150 end end if Playing.Value == true then if getPlayers(BrickColor.new('Bright green')) == 0 or Time.Value == 0 then Function() ----This isn't the actual function. This is actually a different function I did not include in the script wait(4) Function2() ----This isn't the actual function. This is actually a different function I did not include in the script end end end
0
Thank you so much! It works! CoolJohnnyboy 121 — 9y
Ad

Answer this question