Setting a textlabel color to a value

Hi! I just have a simple problem that I need to figure out. Im trying to set a textlabel’s color to a value with this script.

plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(style.MainColor.Value)
			plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB(style.Secondary.Value)
			plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB(style.MainColor.Value)
			plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB(style.Secondary.Value)

But it is giving me an error saying attempt to index string with ‘TextColor3’. Do I need to change it to an int value or what do I need to do? Thanks!

Based on the error, I think that it is setting the TextColor3 property of a string.

I would guess that .Title and .Name property of an Instance returns a string.

1 Like

So what do I need to change in this script?

Are you trying to get the child named Name of the NameTag in NameTag.Name? If so, I’d use FindFirstChild or rename the Name Instance to something else.

I don’t think thats the issue here. The error is that it’s trying to set the color to a string value when it can’t. The “Name” child of Nametag doesn’t have anything to do it.

Properties have a precedent over children and descendants, it’s trying to access the Name property of NameTag, because the child (Name) has the same name as the property. Strings have methods you can call on them such as sub and match, which is what the compiler thinks you’re trying to do.

If you want to get the child (Name) and change the TextColor3 of it, you have to either use FindFirstChild or change the name, as @Blockzez said

2 Likes
plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(tonumber(style.MainColor.Value))
			plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB((tonumber(style.Secondary.Value))
			plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB((tonumber(style.MainColor.Value))
			plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB((tonumber(style.Secondary.Value))

Probably is the issue here. Our advice is to test it out with another name that isn’t the name of a property.

Correction - string only has the __index fallback for OP_GETTABLE; and this is a runtime error so it is in the VM and not the compiler.

But the OP is setting the table and not getting it. In OP’s case, because strings don’t have primitive set operation and the __newindex fallback, OP_SETTABLE resorts to erroring.

1 Like

While I have you guys here, can I ask you for help on another issue? I have been looking for a solution for 4 days. If not, its alright.