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

What is wrong with this rounds script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by 10 years ago

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
0
Adding the .. broke the code, it was underlined in red Mystdar 352 — 10y
1
Than remove it. It's not really needed. Only for some instances. EzraNehemiah_TF2 3552 — 10y
0
You were right, I just had to bracket the string so, example: print ("Hi"..Name.." !") Mystdar 352 — 10y
0
Your welcome. EzraNehemiah_TF2 3552 — 10y
Ad

Answer this question