Help with color changing

This is weird. How can I get this to match up? I have never had this happen before.

The Code: (Local script, starterGui) Notice how the code displays that the colour is pink.

Here is the result: The text is Blue
image

Is the rarity set to Legendary? From what it looks like the colour is matching that of the common rarity.

1 Like

The Rare and Common colors should be Color3.fromRGB(r, g, b). Color3.new(r, g, b) assumes the value 1 to be the maximum, not 255, so for that it’s Color3.new(r/255, g/255, b/255).

I have tried using fromRGB but it failed to work.

Yes, I double checked. All the rarities are correct…

Also, none of the set colours are blue:
Legendary → pink
Rare → red
Uncommon → orange
common → green

Color3 goes from 0 to 1. If you want to use RGB, you have to use Color3.fromRGB(1,1,1)

I did not input the numbers into the color3. I simply dragged the slider until I found the colour I wanted. It wrote the numbers for me. I tried doing fromRGB and it did not work. Again, I have no idea why this is happening.

Did you reference StarterGui in your code or PlayerGui

This is typed within a local script inside of StarterGui

StarterGui is used to store the gui that the player initially has upon spawning in. If you want to reference gui in the game in the manner you described, you need to reference PlayerGui.

I actually had this problem yesterday, here’s how it was fixed:

Here is the entire script, I believe there should be nothing wrong with it :confused:

local function createPetFrame(pet)
	local viewportFrame = script.ViewportFrame:Clone()
	viewportFrame.Parent = script.Parent

	local petImage = pet:Clone()
	petImage.PrimaryPart = pet.Body
	petImage:SetPrimaryPartCFrame(CFrame.new(0, 0, 0)*CFrame.Angles(0, math.rad(60), 0))
	petImage.Parent = viewportFrame

	local viewportCamera = Instance.new("Camera")
	viewportFrame.CurrentCamera = viewportCamera
	viewportCamera.Parent = viewportFrame
	
	local rarity = pet.Configuration.Rarity.Value
	if rarity == "Legendary" then
		viewportFrame.TextLabel.TextColor3 = Color3.fromRGB(242, 48, 255)
	elseif rarity == "Rare" then
		viewportFrame.TextLabel.TextColor3 = Color3.fromRGB(255, 0, 4)
	elseif rarity == "Uncommon" then
		viewportFrame.TextLabel.TextColor3 = Color3.fromRGB(255, 183, 0)
	elseif rarity == "Common" then
		viewportFrame.TextLabel.TextColor3 = Color3.fromRGB(0, 255, 8)
	end
	viewportFrame.TextLabel.Text = rarity .. " " .. pet.Name
	
	viewportCamera.CFrame = CFrame.new(Vector3.new(0, 2, 5), pet.Body.Position)
end

game.ReplicatedStorage.Remotes.PetDataBase.OnClientEvent:Connect(createPetFrame)

Does this same issue happen with the other rarities, or is this just a problem with ‘Legendary’ pet rarities?

It happens to all of them. How odd.

OML. :sweat::flushed: It was never the script. Gosh.

I had a UIGradient inside the label and it was of a blue shade. The colour must have been mixed with the text colour to create another colour. Lol.

1 Like

Have you checked the output for any errors? There’s a chance you’re trying to index an instance that doesn’t exist. For example - your TextLabel may not be named “TextLabel” but instead something like “PetRarity”. Do you mind sending a screenshot of your viewport frame in the explorer with all of it’s children expanded so we can see everything inside?

Ah happens to the best of us. I’m glad you’ve figured it out!

1 Like