TweenPosition is deprecated in favor of TweenService – so you should be using that instead. The old function still works, obviously, but it’s good practice to avoid using deprecated features/functions. Anyways, the reason for your issue is because TweenPosition has an override parameter which is defaulted to false. Since you don’t set this as true, if you move the mouse out of the frame before the MouseEnter tween is completed, the MouseLeave button will play but it wont override the MouseEnter tween. Here’s how you can replace what you have with TweenService:
local tweenservice = game:GetService("TweenService")
local ui = script.Parent
local uioriginal = script.Parent.Position
ui.MouseEnter:Connect(function()
-- TweenInfo.new(time, easingstyle, easingdirection, repeatcount, reverses, delaytime)
tweenservice:Create(ui, TweenInfo.new(0.05, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = UDim2.new(0.021, 0, 0.066, 0)}):Play()
-- rest of code
end)
ui.MouseLeave:Connect(function()
-- TweenInfo.new(time, easingstyle, easingdirection, repeatcount, reverses, delaytime)
tweenservice:Create(ui, TweenInfo.new(0.05, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = uioriginal}):Play()
-- rest of code
end)
-- rest of code
Thank you very much for this I should’ve taken this into consideration and you are correct. I don’t usually use TweenPosition in the first place but in my mind for some reason it made more sense. The advice is much appreciated and you have yourself a fantastic rest of your day/night!