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)

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

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

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)

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

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)
2 Likes

My bad, change

local darkenedColor = changeBrightness(chosenColor)

To

local darkenedColor = changeBrightness(chosenColor.Color)