Making a color3 value darker with a script

Hello! I am experiencing some issues with making the current color3 value darker.

This is the current global script in ServerScriptService.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:FindFirstChild("Torso").BrickColor = BrickColor.random()
		print("changed to", char:FindFirstChild("Torso").BrickColor)
		char:FindFirstChild("Left Leg").Color = char:FindFirstChild("Torso").Color -- how to make it darker?
		char:FindFirstChild("Right Leg").Color = char:FindFirstChild("Torso").Color -- how to make it darker?
	end)
end)
1 Like

I would use Color3 here and then just play with R,G and B values to make it darker.

1 Like

how would i do that? i dont really understand how to mess with rgb values

1 Like
char:FindFirstChild("Left Leg").Color3 = Color3.FromRGB(R,G,B)

R,G,B will be the numbers that you would insert.

Color returns a Color3, a Color3 has R G B properties, you can tweak these to however you want, though I think it would be best to do Color3:ToHSV() and lower the V since (I think) that’s the brightness

Example

local function changeBrightness(color)
	local h, s, v = color:ToHSV()
	return Color3.fromHSV(h, s, v/2) -- Here we half the brightness
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:FindFirstChild("Torso").BrickColor = BrickColor.random()
		print("changed to", char:FindFirstChild("Torso").BrickColor)
		char:FindFirstChild("Left Leg").Color = changeBrightness(char["Left Leg"].Color)
		char:FindFirstChild("Right Leg").Color = changeBrightness(char["Right Leg"].Color)
	end)
end)

the darkening works but not for the set color that gets randomized after the user respawns

Can you explain again? Are you talking about the BrickColor.random()? In that case, simply set the Color property of the Torso to be changeBrightness(BrickColor.random().Color)

1 Like
local function changeBrightness(color)
	local h, s, v = color:ToHSV()
	return Color3.fromHSV(h, s, v/2) -- Here we half the brightness
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:FindFirstChild("Torso").BrickColor = BrickColor.random()
		print("changed to", char:FindFirstChild("Torso").BrickColor)
		char:FindFirstChild("Left Leg").Color =  char:FindFirstChild("Torso").Color
		char:FindFirstChild("Right Leg").Color = char:FindFirstChild("Torso").Color
		changeBrightness(char["Left Leg"].Color)
		changeBrightness(char["Right Leg"].Color)
	end)
end)

this is how its suppose to work but it doesnt.
the Lleg and the Rleg is suppose to be the same color as the torso but darker

1 Like

You need to assign the changeBrightness to the Color property as well

local function changeBrightness(color)
	local h, s, v = color:ToHSV()
	return Color3.fromHSV(h, s, v/2) -- Here we half the brightness
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local chosenColor = BrickColor.random()
		local darkenedColor = changeBrightness(chosenColor.Color)

		char:FindFirstChild("Torso").BrickColor = chosenColor
		print("changed to", char:FindFirstChild("Torso").BrickColor)
		char:FindFirstChild("Left Leg").Color = darkenedColor
		char:FindFirstChild("Right Leg").Color = darkenedColor
	end)
end)
3 Likes

1 Like

My bad, change

local darkenedColor = changeBrightness(chosenColor)

To

local darkenedColor = changeBrightness(chosenColor.Color)