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
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.
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
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
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.