How to make UI TweenPosition not bug out

How to make this stop happening?

I’ve tried adding a debounce and other things but nothing seems to work.

local ui = script.Parent
local uioriginal = script.Parent.Position
local hoverduration = 0.05
local hoversound = script.Parent.Parent.HoverSound
local hoverclick = script.Parent.Parent.HoverClick

local meleelist = script.Parent.Parent.GunSelectionFrame.MeleeList
local riflelist = script.Parent.Parent.GunSelectionFrame.RifleList
local medicallist = script.Parent.Parent.GunSelectionFrame.MedicalList

local sniperlist = script.Parent.Parent.GunSelectionFrame.SniperList
-------------- FUNCTIONS --------------

sniperlist.Visible = false

ui.MouseEnter:Connect(function()
	ui:TweenPosition(UDim2.new(0.021, 0, 0.066, 0), 
		Enum.EasingDirection.InOut, 
		Enum.EasingStyle.Quad, 
		hoverduration)
	
	hoversound:Play()
end)

ui.MouseLeave:Connect(function()
	ui:TweenPosition(
		uioriginal, 
		Enum.EasingDirection.InOut, 
		Enum.EasingStyle.Quad, 
		hoverduration)
end)

--

ui.MouseButton1Click:Connect(function()
	sniperlist.Visible = true
	
	hoverclick:Play()
	
	--

	if  meleelist.Visible == true or medicallist.Visible == true or riflelist.Visible == true then
		meleelist.Visible = false
		meleelist.Visible = false
		medicallist.Visible = false
	end
end)

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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.