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

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

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

2 comments

0

Please point out where the problem is by giving the line that it starts on.

0

I did. I pointed the area of suspected error with green lines saying that this is where I suspect the error to be

1 answer

✓ Accepted answer

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

1 comment

0

Thank you so much! It works!

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