How would I make a part slowly turn black?

I am making a game called arson simulator, and I need to be able to make a sort of ‘charring’ effect whenever something gets set on fire, but instead the parts just turn rainbow.

I have visited dev forum several times to try to find out how to do this, but I have found nothing so far.
Please help.

repeat wait()
	local result = script.Parent
	local c1, c2 = result.Color, Color3.fromRGB(50,50,50)
	if Vector3.new(c1.r,c1.g,c1.b).magnitude >= Vector3.new(c2.r,c2.g,c2.b).magnitude then
		result.Color = Color3.new(result.Color.r + 1, result.Color.g + 1, result.Color.b + 1)
		end
	until Vector3.new(c1.r,c1.g,c1.b).magnitude <= Vector3.new(c2.r,c2.g,c2.b).magnitude

Using Vector3 values are completely unnecessary for slowly turning a part black; this is pretty much all you need to do:

for x = 255, 0, -1 do
	part.Color = Color3.fromRGB(x,x,x)
	wait(0.01)
end

It makes the parts turn completely white, and then they turn black after a while, however I want to preserve the original colour and then turn it black using that.

White is (255,255,255) on RGB, and black is (0,0,0); this script works by subtracting the R, G, and B values until they equal 0.

local start = part.Color

for _ = 0, 255 do
	part.Color = Color3.fromRGB(start.R-1,start.G-1,start.B-1)
	wait(0.01)
end

@bartkor12 I made a mistake on the first one and I edited it; try it now.

yes it does indeed work as I have stated but it turns the part white and then black, and I want the original colour of the part to still be visible instead of making it monotone

1 Like

HSV can usually do the trick here, as well as a RunService connection for smoothing the effect.

local RunService = game:GetService("RunService")

-- Constant
local CHAR_RATE = 0.2

-- Make a part darker by lowering it's color's value
local function Char(part: BasePart, delta: number)
	local h, s, v = part.Color:ToHSV()
	part.Color = Color3.fromHSV(h, s, math.max(v - delta, 0))
end

-- Burn a part by connecting it to a RunService connection until it's value is completely black.
local function BurnPart(part: BasePart)
	local connection: RBXScriptConnection; connection = RunService.Heartbeat:Connect(function(dt: number)
		local _, _, v = part.Color:ToHSV()
		if v <= 0 then
			connection:Disconnect()
			return
		end
		Char(part, dt * CHAR_RATE )
	end)
end
2 Likes
local part = workspace:WaitForChild("Part")
local color = part.Color
local count = 0

repeat
	task.wait(0.1)
	part.Color = Color3.fromRGB(math.round(color.R * 255)+count, math.round(color.G * 255)+count, math.round(color.B * 255)+count)
	count-=1
until part.Color.R <= 0 and part.Color.G <= 0 and part.Color.B <= 0

task.wait(10)
part.Color = color

This retains the original color and slowly transitions to black, then waits 10 seconds and reverts back to the original color.

Generally you shouldn’t be connecting to RunService unless a situation explicitly requires it (like camera updates / pre physics simulation changes). Is there anything wrong with using TweenService here? You can’t read TweenService source, but I would be surprised if :Play() didn’t run per frame anyways.