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

Round system error - I have no clue how to fix? Help needed ASAP. [SOLVED]

Asked by
KordGamer 155
9 years ago

I'm writing a round script for my new game, And I came across an error while sorting the teams: 08:31:38.422 - Workspace.GameScript:41: bad argument #3 to 'TeamColor' (BrickColor expected, got userdata)

I have no clue how to fix it. Here is the script itself : [Some parts are cut off]

--Varibales--
Text = game.Lighting.Text1
Maps = {"Testing", "Testing 2"}
NumMaps = 2
--------------
--------Script--------

if not game.Players then
    Text.Value = "Oh no! There is not enough players to continue..."
else
    Text.Value = "Welcome to the game! A new game is starting in a couple of seconds..."
    wait(3)
    Text.Value = "Picking map..."
    wait(2)
    RandomChoice = math.random(1, NumMaps)
    CurrentMap = Maps[RandomChoice]
    ChosenMap = game.ServerStorage:FindFirstChild(CurrentMap)
    ChosenMap:clone().Parent = game.Workspace
    ChosenMap.Name = "Map"
    Text.Value = "The map selected is : "..CurrentMap.."!"
    wait(3)
    Text.Value = "Preparing your spawn areas..."
    wait(2)
    Text.Value = "Sorting you into teams..."
    Teams = {
    teamRed = game:GetService("Teams")["Red Bloxxers"],
    teamBlue = game:GetService("Teams")["Blue Bloxxers"]
    }
    function ScrambleTeams() --Here is where the team sorting begins
       local plrs = game.Players:GetPlayers()
       local plrsNew = {}
        --Scramble table:
        while (#plrs > 0) do
            local i = math.random(#plrs)
            table.insert(plrsNew, plrs [i])
            table.remove(plrs, i)
        end
      local teamEven = (math.random() < 0.5 and Teams.teamRed or Teams.teamBlue)
     local teamOdd = (teamEven == Teams.teamRed and Teams.teamBlue or Teams.teamRed)
      for i,p in pairs(plrsNew) do
        p.TeamColor = ((i % 2) == 0 and teamEven or teamOdd) --Here is the error
    end
end
    ScrambleTeams()
    for i = 15, 1, -1 do
    Text.Value = "Time left : "..i.." seconds"
    wait(1)
end
end

Any help is appreciated, Thanks!

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

You're trying to set the TeamColor property of the player to the Team object. You have to index the TeamColor property of the Team object as well!

p.TeamColor = (((i % 2) == 0 and teamEven.TeamColor) or teamOdd.TeamColor)
0
Thanks for the answer, But now it doesn't even sort... KordGamer 155 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

As well as indexing the Team's TeamColor like Goulstem suggested, try removing some of your parenthesis as some of them don't need to be there.

p.TeamColor = (i % 2 == 0) and teamEven.TeamColor or teamOdd.TeamColor
0
Liked your answer too :D KordGamer 155 — 9y
0
Glad you got it working. Spongocardo 1991 — 9y

Answer this question