How would I lerp between two colors smoothly?

Hi there, I have a script that lerps between two colors using playbackloudness. Issue is, is that it doesn’t lerp smoothly and doesn’t transition through enough colors. I do not have a current attempt as I do not understand why this is happening.

Credits to @AC_Starmarine and @JaceMorphing for helping me come to a solution

local sound = workspace.Sound
local parts = workspace:WaitForChild("parts")
local floor = parts:WaitForChild("Club Floor")
local ColorSilent = Color3.fromRGB(0, 0, 0)
local ColorLoud = Color3.fromRGB(10, 162, 243)

task.spawn(function()
	while task.wait() do
		local fractionAlpha = sound.PlaybackLoudness / 150
		if fractionAlpha > 1 then
			fractionAlpha = 1
		end
		floor.Color = ColorSilent:Lerp(ColorLoud, fractionAlpha)
		print(sound.PlaybackLoudness)
	end
end)

Try:


local sound = workspace.Sound

local parts = workspace:WaitForChild("parts")

local floor = parts:WaitForChild("Club Floor")

local ColorSilent = Color3.fromRGB(0, 0, 0)

local ColorLoud = Color3.fromRGB(10, 162, 243)

local rs = game:GetService("RunService")

local lastSoundLevel = sound.PlaybackLoudness

rs.Heartbeat:Connect(function()

local difference = sound.PlaybackLoudness - lastSoundLevel

difference /= 100

difference = math.clamp(difference,0,1)

floor.Color = ColorSilent:Lerp(ColorLoud,difference)

end)
2 Likes

What is happening in this script? Can you please explain the differences please?

Also, it isn’t really smoother at all. Sorry

He math.clamps the difference between 0 and 1 so it doesn’t go above 1 or below 0 and then lerps your ColorSilent to ColorLoud with difference

Try to change math.clamp(difference,0,1) to math.clamp(difference,0.3,1)

it does seem a bit more smoother now, I’ll keep playing around with the numbers.

I changed it to 0.5 and it’s so smooth now

You didn’t change math.clamp(difference,0,1) to math.clamp(difference,0.3,1), I have tried this and It works fine and smooth.

Just did

Code I tested :

local sound = workspace:WaitForChild("Flushed")

sound:Play()

while task.wait() do

script.Parent.Color = script.Parent.Color:Lerp(Color3.fromRGB(math.clamp(sound.PlaybackLoudness / 2,10,255),0,0),math.clamp(sound.PlaybackLoudness,0.3,1))

end

I think you can do that with TweenService. They have plenty of EasingStyles to choose from.

I had to untick solution because now I’ve ran into another problem. Is there a way I can adjust the maxloudness of this? The loudness of the playbackloudness is a bit high.

I’ve tried that, but I ran into problems because of looping (I can’t really explain it)

But if I were, how would I use it?

Instead of “true”, just put “false” in TweenInfo. That way, it won’t “reverse” or loop in other words when it finishes the task.

Would you loop it indefinitely or just keep it at zero?

Use math.clamp() or divide Loudness by any number.

like this?

local sound = workspace.Sound
local parts = workspace:WaitForChild("parts")
local floor = parts:WaitForChild("Club Floor")

local ColorSilent = Color3.fromRGB(0, 0, 0)
local ColorLoud = Color3.fromRGB(10, 162, 243)

local rs = game:GetService("RunService")

local lastSoundLevel = sound.PlaybackLoudness

local pl = sound.PlaybackLoudness / 10

rs.Heartbeat:Connect(function()

	local difference = pl - lastSoundLevel

	difference /= 100

	difference = math.clamp(difference,0.5,1)

	floor.Color = ColorSilent:Lerp(ColorLoud,difference)

end)

Change difference variable to be like this : local difference = (sound.PlaybackLoudness / 4) - lastSoundLevel

You can change number 4 in the variable to any number you wan’t, but 4 works fine for me.