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

What is wrong with this rounds script?

This is a Normal Script in the Workspace

--[[Rounds]]
--[[Tables]]
BrickColors = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")} 
function Team()
	--[[Number of players in each team]]
	for i,v in pairs(game.Players:GetChildren()) do
		WhiteTeam = 0
		BlackTeam = 0
			if v.TeamColor == BrickColor[1] then
				WhiteTeam = WhiteTeam + 1
			elseif v.TeamColor ==  BrickColor[2] then
				BlackTeam = BlackTeam + 1
			end
		--[[Putting players on Teams]]
		if WhiteTeam < BlackTeam then
	        v.TeamColor = BrickColor[1]
	        WhiteTeam = WhiteTeam + 1 
	    elseif WhiteTeam > BlackTeam then
	        v.TeamColor = BrickColor[2]
	        BlackTeam = BlackTeam + 1 
	    else
	        v.TeamColor = BrickColor[1]
	        WhiteTeam = WhiteTeam + 1
	    end
	end
	print "There are "WhiteTeam" players on the White Team"
	print "There are "BlackTeam" players on the Black Team"
end	

--[[Reseting Players]]
function Reset()
	for i,v in pairs(game.Players:GetChildren()) do
		v.TeamColor = BrickColors[3]
	end
end

--[[Firing]]
while true do
	wait(4)
	Reset()
	wait(5)
	Team()
end

Output:

20:46:57.786 - Workspace.Script:22: bad argument #3 to 'TeamColor' (BrickColor expected, got nil)

20:46:57.788 - Script 'Workspace.Script', Line 22 - global Team

20:46:57.789 - Script 'Workspace.Script', Line 42

20:46:57.790 - Stack End

Also if you know a way to make this more efficient, please improve/tell me.

EDIT: Line 3 I was using BrickColor**s** value, and calling BrickColor throughout the script, and you were right about the .. I just had to bracket the string

1 answer

✓ Accepted answer

Try this. Tell me if it doesn't work.

--[[Rounds]]
--[[Tables]]
BrickColors = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")}
function Team()
    --[[Number of players in each team]]
    for i,v in pairs(game.Players:GetChildren()) do
        WhiteTeam = 0
        BlackTeam = 0
            if v.TeamColor == BrickColors[1] then
                WhiteTeam = WhiteTeam + 1
            elseif v.TeamColor ==  BrickColors[2] then
                BlackTeam = BlackTeam + 1
            end
        --[[Putting players on Teams]]
        if WhiteTeam < BlackTeam then
            v.TeamColor = BrickColors[1]
            WhiteTeam = WhiteTeam + 1 
        elseif WhiteTeam > BlackTeam then
            v.TeamColor = BrickColors[2]
            BlackTeam = BlackTeam + 1 
        else
            v.TeamColor = BrickColors[1]
            WhiteTeam = WhiteTeam + 1
        end
    end
    print "There are "..WhiteTeam.." players on the White Team"
    print "There are "..BlackTeam.." players on the Black Team"
end 

--[[Reseting Players]]
function Reset()
    for i,v in pairs(game.Players:GetChildren()) do
        v.TeamColor = BrickColors[3]
    end
end

--[[Firing]]
while true do
    wait(4)
    Reset()
    wait(5)
    Team()
end

4 comments

0

Adding the .. broke the code, it was underlined in red

1

Than remove it. It's not really needed. Only for some instances.

0

You were right, I just had to bracket the string so, example: print ("Hi"..Name.." !")

0

Your welcome.

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