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

Making a dynamic team changer, stuck on changing the color. Fix?

Hey there people of the world! I've had a few months break from writing lua, so my knowledge isn't the best right now, i'm wondering how to change the color of my text label while creating buttons for my team changer.

My error is "Unable to cast int to int"

No idea what that means.

My current script:

Line 13, btw.

-- Dynamic team changer created by BashGuy10

-- Create teams inside the teams service, with a boolen value called "TeamChange", setting to true means the team will show on the team changer, setting it to false.

local players = game:GetService("Players")
local localplayer = players.LocalPlayer
local teams = game:GetService("Teams")
local template = script.Parent.Template


for i, v in pairs(teams:GetChildren()) do
	if v:WaitForChild("TeamChange").Value then
		local clone = template:Clone()
		
		template.Parent = script.Parent.Frame.TeamFrame
		template.Name = v.Name
		template.TextColor3 = Color3(BrickColor.palette(v.TeamColor))
		template.TextTransparency = 0
	end
end

4 comments

0

try replacing teams:GetChildren() with teams:GetTeams() since you're trying to get the teams, not the children. if you have something else besides a team inside of game.Teams, you might run into an error . your variable teams is a bit ambiguous as well. it suggests that teams is a table containing the teams, but it's actually the teams service. You are also changing the parent/name/text of vvvv

0

the template instead of the clone. Is this intentional?

0

oh i forgot to change that while writing it lol

0

it ok. i replied to ur post if you havent seen it yet. you went offline as soon as i posted :( 

1 answer

✓ Accepted answer

Your error comes from line 17 where you are saying BrickColor.palette(v.TeamColor)

BrickColor.palette takes in a number 0-127 since there are 128 possible brick colors.

With this code, you can print out all the possible BrickColors:

for i = 0, 127 do
	print(i, BrickColor.palette(i))
end

Not sure why this constructor is a thing. I think it has something to do with how the brick colors used to be displayed in a hexagonal shape in studio a couple years back before they added support for Color


Anyway, you are getting the error because you're trying to pass in a BrickColor instead of a number into the function. You'd get the same error if you tried to print the following:

print(BrickColor.palette(BrickColor.new("White")))

Also, that's not the right way to convert a brick color to a color3, you should be saying

local myBrickColor = BrickColor.new("White")
myBrickColor.Color

You should end up your code to the following:

template.TextColor3 = BrickColor.palette(A NUMBER 0-127).Color

#EDIT: Op wanted to make the template's color be the teams color: template.TextColor3 = v.TeamColor.Color

2 comments

0

Is there anyway i can get the palette number from inserting a brickcolor value into a function? As i want this to be dynamic, not having to input all of the numbers individually.

0

i'm not sure what you're trying to achieve exactly. you want to give each team their own color?

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