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

Broken script - How to get team name?

Hello, I am trying to fix a script to get the team name from the team color.

local playerTeamColor = player.TeamColor
for i,v in pairs (game.Teams:GetChildren()) do
	if v.TeamColor == BrickColor.new(Colour3.new(playerTeamColor)) then
		local playerTeamName = v.Name
	end
end

When this script runs, It returns the following:

14:19:23.553 - Players.Player1.PlayerGui.ScreenGui.Main.LocalScript:9: bad argument #1 to 'new' (Color3 expected, got userdata)

14:19:23.553 - Script 'Players.Player1.PlayerGui.ScreenGui.Main.LocalScript', Line 9 - global UpdateTeam

14:19:23.554 - Script 'Players.Player1.PlayerGui.ScreenGui.Main.LocalScript', Line 22

14:19:23.555 - Stack End

Please help and fix this,

Regards, devSparkle

2 answers

To add on to what LocailLua said, there is no reason to use Color3 at all. TeamColor is a BrickColor value, so there is no reason to change it to Color3.

Also, your player variable is not defined anywhere in the script, unless you have more code around that of course.

Anyways, do the check like this:

 if v.TeamColor == playerTeamColor then

1 comment

0

Thanks, I fixed it using "tostring"

Apparently, ROBLOX was treating player.Teamcolor as a UserData value. When this happens, it's best to translate the userdata to a string, by using tostring(VALUENAME). This makes ROBLOX identify it as a string (plain text), making it comparable.

local playerTeamColor = tostring(player.TeamColor)
for i,v in pairs (game.Teams:GetChildren()) do
    if v.TeamColor == BrickColor.new(playerTeamColor) then
        local playerTeamName = v.Name
    end
end

1 comment

0

Should not be necessary, you should be able to directly compare one to the other.

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