I’m tweening the color of many parts, using tweenservice for this is very laggy and unoptimized, how would I change the color of the parts without the use of tweens?
1 Like
Use lerping (linear interpolation)
1 Like
i tried, it doesnt really do anything for some reason
1 Like
actually, let me try again
(it didnt work)
30charahaudhkasjh
2 Likes
Did you use the :Lerp
method on the Color3
?
example use:
local duration = 2 -- Duration
local elapsed = 0
local parts = {part1, part2, part3} -- Replace with your parts
local function lerpColor(startColor, endColor, alpha)
return startColor:Lerp(endColor, alpha)
end
while elapsedTime < duration do
local alpha = elapsed / duration
local currentColor = lerpColor(startColor, endColor, alpha)
for _, part in ipairs(parts) do
part.Color = currentColor
end
elapsed = elapsed + game:GetService("RunService").Heartbeat:Wait()
end
3 Likes
Yeah, you might not be doing it right. If you want to keep colours the same brightness, you can lerp the hue
value of a HSV colour, or otherwise use the :Lerp()
function of Color3
like @VonsRevenges suggested.
Basic lerping function
local function lerp(startVal: number, endVal: number, alpha: number): number
return startVal + (endVal - start) * alpha
end
im gonna ask something crazy.
mind sharing a video of the tweenservice being laggy?
and your associated code.
1 Like