My tween is not working

Hello. I am having an issue when trying to tween a UI’s BackgroundColor3 when MouseEnter and MouseLeave events are fired. Here is my code:

local frame = script.Parent;

local tweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	1
)

local goals = {
	BackgroundColor3 = Color3.new(90, 0, 135)
}

local tween1 = tweenService:Create(frame, tweenInfo, goals)

local goals2 = {
	BackgroundColor3 = Color3.new(170, 0, 255)
}

local tween2 = tweenService:Create(frame, tweenInfo, goals2)

local function on_Enter()
	
	tween1:Play()
end

frame.MouseEnter:Connect(on_Enter)

local function on_Leave()
	
	tween2:Play()
end

frame.MouseLeave:Connect(on_Leave)

The tween is actually playing, but you can’t see it because you’re not using the right Color3 conversion. You’re defining a color by RGB where R, G, and B are 0-255, but in the code, you’re defining it as Color3.new, which is completely different. Color3.new only takes in values from 0-1 for R, G, and B, and you’re using 0-255 RGB numbers, meaning you’re not going to see anything since the color is way over the max because you used Color3.new.

To fix this, simply change the Color3.new’s to Color3.fromRGB and put the same numbers you had before.

3 Likes