I'm new at scripting, what's wrong with this script?

So currently I’m making a UI button, and at the moment I want it so when the mouse enters the button it fades to one colour, and when it leaves it fades back. I’ve got this simple script I’ve rushed up, and yes, it’s a mess. This is just so I can get a script that is working and then do some housekeeping later. Here is the script I currently have.

local Button = script.Parent
local Text = script.Parent.ButtonText
local TweenService = game:GetService("TweenService")
local transitionInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
local enabled = false

Button.MouseEnter:Connect(function()
	if enabled == false then
		local tween = TweenService:Create(Button, transitionInfo, {BackgroundColor3 = Color3.fromRGB(255, 255, 255)})
		tween:Play()
		
		local tween2 = TweenService:Create(Text, transitionInfo, {TextColor3 = Color3.fromRGB(36, 36, 36)})
		tween2:Play()
		enabled = true
		print("Done")
	else
		print("Already on")
	end
end)

Button.MouseLeave:Connect(function()
	if enabled == true then
		local tween = TweenService:Create(Button, transitionInfo, {BackgroundColor3 = Color3.fromRGB(36, 36, 36)})
		tween:Play()
		
		local tween2 = TweenService:Create(Text, transitionInfo, {TextColor3 = Color3.fromRGB(255, 255, 255)})
		tween2:Play()
		enabled = false
		print("Done")
	else
		print("Already off")
	end
end)

When my mouse leaves the button, it should fade back to the original colour, but instead it fades back to black, then the original colour. This is likely simple to most people, but I’m just new with lua. I’d love any feedback. https://gyazo.com/7e1a37ec349b2c4d9cd645476001b4af

1 Like

When I’m right it could be because of your transitionInfo. You should change it to anything else then Enum.EasingStyle.Back then it could probably work.

1 Like

Sorry about that. Thank you very much!