How can I correctly debounce a Gui when using MouseEnter and MouseLeave

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make a Frame that MouseEnter and MouseLeave correctly without getting it stuck in a certain size.
  2. What is the issue? Include screenshots / videos if possible!
    Make a Frame not get stuck in a certain size when using MouseEnter and MouseLeave
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking for answers in DevForum and ScriptingHelpers, I tried some solutions but none of them really did what I was asking for.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Frame = script.Parent.Frame
debounce = true

function Hov()
	
	
	while wait(0.1) do
		if debounce then
			break
		end
	end
	Frame:TweenSize(UDim2.new(0, 100,0, 100), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear,0.3)
end

debounce = true

Frame.MouseLeave:Connect(Hov)

function HovE()
	while wait(0.1) do
		if debounce then
			break
		end
	end
	
	Frame:TweenSize(UDim2.new(0, 200,0, 200), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear,0.3)
end

Frame.MouseEnter:Connect(HovE)

debounce = true

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.Preformatted text

I am still learning how to script in Lua and I find it really fun.

Thank you very much replying, someone helped me with this just now.

local HOVER_SIZE = UDim2.new(0, 200, 0, 200)
local LEAVE_SIZE = UDim2.new(0, 100, 0, 100)

local frame = script.Parent:WaitForChild("Frame", nil)

frame.MouseEnter:Connect(function(x, y)
  frame:TweenSize(HOVER_SIZE, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true, nil)
end)
frame.MouseLeave:Connect(function(x, y)
  frame:TweenSize(LEAVE_SIZE, Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 0.3, true, nil)
end)```
1 Like
local Frame = script.Parent
local OriginalSize = Frame.Size
local HoverOffset = UDim2.fromOffset(200, 200)
local Tween = nil
Frame.MouseEnter:Connect(function()
	if Tween ~= nil then Tween:Destroy() end
	Tween = game:GetService("TweenService"):Create(Frame, TweenInfo.new(0.3), {Size = (OriginalSize + HoverOffset)})
	Tween:Play()
end)
Frame.MouseLeave:Connect(function()
	if Tween ~= nil then Tween:Destroy() end
	Tween = game:GetService("TweenService"):Create(Frame, TweenInfo.new(0.3), {Size = OriginalSize})
	Tween:Play()
end)

Example :