Color3.FromHSV() tweening problems

local TweenService = game:GetService('TweenService')

local function tweenTextHue(object, timeDuration, repeating, repeatAmount,		hue, saturation, lightness)
	local goal = {
		TextColor3 = Color3.new( Color3.FromHSV(hue, saturation, lightness) );
	}
	local tweenInfo = TweenInfo.new(
		timeDuration,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		repeatAmount,
		repeating,
		0
	)
	
	local tween = TweenService:Create(object, tweenInfo, goal)
	tween:Play()
	
	return tween
end

local dog = script.Parent:WaitForChild('dog')
local hat = dog:WaitForChild('hat')
local label = script.Parent:WaitForChild('TextLabel')

local labelColor = label.TextColor3

------------ Main
while true do
	wait(2)
	tweenTextHue(labelColor, 5, true, -1,		359, 255, 255)
	wait(12)
end

labelColor is set to have the properties hue:0, sat: 255, val:255, red:255. If tweened to the parameters in the function call above, an infinite, smooth change in hue to the parameter values from the original should be displayed. When calling the function, however, the error attempt to call a nil value is given.

Now correct me if I’m wrong, but I’m pretty sure hsv can only be a value from 0-1 > RGB values are 0-255 .

1 Like

Actually no I wasn’t wrong, Color3 | Documentation - Roblox Creator Hub

I think that this code will not work as expected. Color3.FromHSV is a constructor the same way that Color3.new is. You are essentially putting a Color3 value into a constructor for a Color3.

Thank you. Even so, TextColor3 = Color3.FromHSV(hue, saturation, lightness); gives the same error.

Which line is the error on? (Post must be at least (29+1) characters long)

Color3.fromRGB is the only color3 constructor which uses 0-255. Color3.new + Color3.fromHSV use 0-1. Easiest solution would be to divide the numbers by 255, if that’s what they are out of.

1 Like

This variable is a color3 value, but when you pass it into your function, you treat it like it is an object. Instead try just passing label as the first parameter to your function.

This “repeating” variable is miss-named. The api for creating a TweenInfo uses that 5th parameter for the tween reversing once reaching the goal.

Likewise, you will have a this tween repeating automatically by using a negative repeat count which causes it to repeat indefinitely. This function is called repeatedly in a loop at the bottom of your script which might cause weird conflicts.

You can read more about the tween service API at the bottom of this page. TweenService

Thank you. I’ve taken the errors found into account, but the error still occurs at line 6 (TextColor3 = Color3.FromHSV(hue, saturation, lightness);). Here’s the updated code:

------------ Functions
local TweenService = game:GetService('TweenService')

local function tweenTextHue(object, timeDuration, repeating, repeatAmount,		hue, saturation, lightness)
	local goal = {
		TextColor3 = Color3.FromHSV(hue, saturation, lightness);
	}
	local tweenInfo = TweenInfo.new(
		timeDuration,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		repeatAmount,
		repeating,
		0
	)
	
	local tween = TweenService:Create(object, tweenInfo, goal)
	tween:Play()
	
	return tween
end



local dog = script.Parent:WaitForChild('dog')
local hat = dog:WaitForChild('hat')
local label = script.Parent:WaitForChild('TextLabel')

------------ Main

	wait(2)
	tweenTextHue(label, 5, false, 0,		1, 1,1)
	wait(12)

Ah Yeah!

Use Color3.fromHSV() instead of Color3.FromHSV()

1 Like