Color3 Fails to Color3

  1. What do you want to achieve?
    I’m making a game where you invade countries, and when you hover over a tile of each country, it should get brighter.

  2. What is the issue?
    The issue is on some countries, like Belgium and the Philippines, the color will be nowhere near the correct color, like hovering over a yellow Belgian tile causes it to turn green, and hovering over a banana-colored Ukraine tile turns it blue.

  3. What solutions have you tried so far?
    I’ve looked on Google, Bing, the Developer Hub, and nothing helped.
    It just told me the same thing that would happen. Here is my code.

clickDetector.MouseHoverEnter:Connect(function(player)
		local color = provincePart.Color
		local red = color.R*255
		local blue = color.B*255
		local green = color.G*255
		provincePart.Color = Color3.fromRGB(red+30, green+30, blue+30)
		provincePart.Material = Enum.Material.Neon

		showProvinceInfo:FireClient(player, provinceInfo, provincePart.Position)
	end)

it probably happens becuase the color values go over 255

for each color value you can cap it at 255 with

math.min(255, col + 30)

so it would be

Color3.fromRGB(
  math.min(255, red + 30),
  math.min(255, green + 30),
  math.min(255, blue + 30)
)
1 Like

just use HSV instead Color3 | Documentation - Roblox Creator Hub Color3 | Documentation - Roblox Creator Hub
ETC:

local h,s,v = country_color:ToHSV()
local howerColor = Color3.fromHSV(h,s,math.max(v-0.2,0))

Also firing that to a client is awfullest idea ever.
Just calculate it on a client because if you are making a game like HOI4, it will make network bandwidth completely full.

	local color = provincePart.Color
	local red = math.clamp(color.R * 255 + 30, 0, 255)
	local green = math.clamp(color.G * 255 + 30, 0, 255)
	local blue = math.clamp(color.B * 255 + 30, 0, 255)

	provincePart.Color = Color3.fromRGB(red, green, blue)
	provincePart.Material = Enum.Material.Neon

	showProvinceInfo:FsireClient(player, provinceInfo, provincePart.Position)
end)```

Instead of adding fixed values, use Color3:Lerp to blend the current color toward white

clickDetector.MouseHoverEnter:Connect(function(player)
	local originalColor = provincePart.Color
	local brighterColor = originalColor:lerp(Color3.new(1, 1, 1), 0.25)
	provincePart.Color = brighterColor
	provincePart.Material = Enum.Material.Neon

	showProvinceInfo:FireClient(player, provinceInfo, provincePart.Position)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.