Hover GUI script not turning out how I want it to be

Making a menu and I want it to have this cool hover effect. I’ve played with a hover effect with gui in the past and knew what I was doing. Well all of a sudden it doesn’t do what I want it to do. I have no idea what I have done wrong. Local script is inside the gui.

https://gyazo.com/e14f34a9c8696b86ad3f4eecad77b6b2

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 350,0, 165),"Out","Linear",0.2, true)
	script.Parent.CasualButton:TweenSize(UDim2.new(0, 316,0, 75),"Out","Linear",0.2, true)
	script.Parent:TweenPosition(UDim2.new(0.047, 0,0.269, 0),"Out","Linear",0.2,true)
	script.Parent.ImageColor3 = Color3.new(1, 1, 1)
	script.Parent.CasualButton.TextColor3 = Color3.new(0, 0, 0)
	  
end)

script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0, 334,0, 100),"Out","Linear",0.2, true)
	script.Parent.CasualButton:TweenSize(UDim2.new(0, 245,0, 40),"Out","Linear",0.2, true)
	script.Parent:TweenPosition(UDim2.new(0.757, 0,0.753, 0),"Out","Linear",0.2,true)
	script.Parent.CasualButton:TweenPosition(UDim2.new(0.128, 0,0.299, 0),"Out","Linear",0.2,true)
	script.Parent.ImageColor3 = Color3.new(0, 0, 0)
	script.Parent.CasualButton.TextColor3 = Color3.new(1, 1, 1)

end)```

The GuiObject instance you’ve used for your MouseEnter/MouseLeave events is also being tweened by callback functions connected to those same events, this seems to be causing both events to fire rapidly as the mouse is repetitively entering/leaving the GuiObject’s frame.

So how can I possibly fix this?

local GuiObject = script.Parent
local Running = false

GuiObject.MouseEnter:Connect(function()
	if Running then
		return
	end
	
	Running = true
	GuiObject:TweenSize(UDim2.new(0, 350, 0, 165),"Out","Linear",0.2, true)
	GuiObject.CasualButton:TweenSize(UDim2.new(0, 316, 0, 75),"Out","Linear",0.2, true)
	GuiObject:TweenPosition(UDim2.new(0.047, 0, 0.269, 0),"Out","Linear",0.2,true)
	GuiObject.ImageColor3 = Color3.new(1, 1, 1)
	GuiObject.CasualButton.TextColor3 = Color3.new(0, 0, 0)
	task.wait(0.2)
	Running = false
end)

GuiObject.MouseLeave:Connect(function()
	if Running then
		return
	end

	Running = true
	GuiObject:TweenSize(UDim2.new(0, 334, 0, 100),"Out","Linear",0.2, true)
	GuiObject.CasualButton:TweenSize(UDim2.new(0, 245, 0, 40),"Out","Linear",0.2, true)
	GuiObject:TweenPosition(UDim2.new(0.757, 0, 0.753, 0),"Out","Linear",0.2,true)
	GuiObject.CasualButton:TweenPosition(UDim2.new(0.128, 0, 0.299, 0),"Out","Linear",0.2,true)
	GuiObject.ImageColor3 = Color3.new(0, 0, 0)
	GuiObject.CasualButton.TextColor3 = Color3.new(1, 1, 1)
	task.wait(0.2)
	Running = false
end)

Something like a debounce/state check which prevents the functions from executing over each other.

local GuiObject = script.Parent
local Running = false

GuiObject.MouseEnter:Connect(function()
	if Running then
		task.wait(0.2)
		Running = false
	end
	
	Running = true
	GuiObject:TweenSize(UDim2.new(0, 350, 0, 165),"Out","Linear",0.2, true)
	GuiObject.CasualButton:TweenSize(UDim2.new(0, 316, 0, 75),"Out","Linear",0.2, true)
	GuiObject:TweenPosition(UDim2.new(0.047, 0, 0.269, 0),"Out","Linear",0.2,true)
	GuiObject.ImageColor3 = Color3.new(1, 1, 1)
	GuiObject.CasualButton.TextColor3 = Color3.new(0, 0, 0)
end)

GuiObject.MouseLeave:Connect(function()
	if Running then
		task.wait(0.2)
		Running = false
	end

	Running = true
	GuiObject:TweenSize(UDim2.new(0, 334, 0, 100),"Out","Linear",0.2, true)
	GuiObject.CasualButton:TweenSize(UDim2.new(0, 245, 0, 40),"Out","Linear",0.2, true)
	GuiObject:TweenPosition(UDim2.new(0.757, 0, 0.753, 0),"Out","Linear",0.2,true)
	GuiObject.CasualButton:TweenPosition(UDim2.new(0.128, 0, 0.299, 0),"Out","Linear",0.2,true)
	GuiObject.ImageColor3 = Color3.new(0, 0, 0)
	GuiObject.CasualButton.TextColor3 = Color3.new(1, 1, 1)
end)

Similar logic with a slightly different approach.

Thank you very much, this fixed the problem perfectly!