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

Local Team Changer Not Working?

Asked by 9 years ago

This script is a (horribly Failed) attempt at a team changer as a addition onto my local script. Thanks for reading. Code here(I know its bad)

if workspace.Gamestart == true then
Rteam = BrickColor.new("Bright red")
Bteam = BrickColor.new("Bright blue")
Teams = {Rteam,Bteam}
local plr = game:GetService("Players").LocalPlayer
plr.TeamColor = Teams[math.random(#Teams)]
end
0
Line 2-3 are just `string` formats. woodengop 1134 — 9y

2 answers

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

You used the wrong type of Color Format for the teams. You need to use proper BrickColor formatting. Try this instead:

Rteam = BrickColor.new("Bright red")
Bteam = BrickColor.new("Bright blue")

Also, you used math.random incorrectly to get the team. To fix this, let's put this in:

plr.TeamColor = Teams[math.random(#Teams)]

Anyways, I believe it should work now. If you have any further questions/problems, please leave a comment below! Hope I helped :P

0
It seems not to be running inside my local script? No errors, its all correct, just not running properly? any ideas? ioutragous 0 — 9y
0
Hmm...make sure that workspace.Gamestart is set to true. That's the only problem I can see. And also make sure there's an "end" at the end of this code block. dyler3 1510 — 9y
0
I still dont seem to have it working both teams have auto assigning off so every starts as nuatral, i updated it to the most recent code block. Any Ideas now? ioutragous 0 — 9y
0
Can you message me on Roblox so I can get some more information about what's going on? dyler3 1510 — 9y
Ad
Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

Problem

You are simply attempting to set the player's TeamColor property to whatever string is returned by the randomly generated value from table Teams. In order for your assignment to work, your random TeamColor must be a BrickColor data type, which you can set using its .new constructor function.

The random function of the math library works one of three ways..

  1. No argument: Calling it with no supplied argument would returned a uniformly distributed pseudo-random numbers.

  2. One argument "maximum": Calling it with just one argument would return a uniform pseudo-random integer in ranging from 1 to maximum.

  3. Two arguments "minimum, maximum": Calling it with two arguments would return a uniform pseudo-random integer ranging from minimum to maximum

All arguments must be integers. Your code isn't functioning as expected because you are passing a table, team, as argument to the function instead of the length of said table, with can be determined using the length operator (#).

Solution

local redTeam, blueTeam = BrickColor.new("Bright red"), BrickColor.new("Bright blue")
local player = game:GetService("Players").LocalPlayer

local teams = {redTeam, blueTeam}
player.TeamColor = teams[math.random(1, #teams)]

You could also assign a variable to the TeamColor for use later on in your script.. by storing the pseudo-random integer before indexing it.

local redTeam, blueTeam = BrickColor.new("Bright red"), BrickColor.new("Bright blue")
local player = game:GetService("Players").LocalPlayer

local teams = {redTeam, blueTeam}
local color = math.random(1, #teams)
player.TeamColor = teams[color]

print(player.Name, "has been assigned to the", tostring(color),"team")
0
Thanks its working but its not changing on the leaderboard, but the team's tools are being given ioutragous 0 — 9y
0
What? Their TeamColor is changed but not on the leaderboard? Are you using roblox's default board? ImageLabel 1541 — 9y

Answer this question