MouseEnter & Leave are buggy

I have buttons using these functions and I was having problems with mouseleave because it doesn’t sometimes tween the button back. I found a module from here and used it, but still having the same issues.

Code:

local MouseOverModule = require(game.ReplicatedStorage.MouseOverModule)

local MouseEnter, MouseLeave = MouseOverModule.MouseEnterLeaveEvent(script.Parent)
MouseEnter:Connect(function()
	script.Parent.Parent.Parent.Sounds.Hover:Play()
	script.Parent:TweenSize(UDim2.new(0.041, 0,0.094, 0), "In", "Linear", 0.1)
end)

MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0.037, 0,0.087, 0), "In", "Linear", 0.1)
end)

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Parent.Shop.Visible ~= true then
		script.Parent.Parent.Parent.Sounds.Click:Play()
		wait(0.1)
		script.Parent.Parent.Parent.Shop.Visible = true
		script.Parent.Parent.Parent.Sounds.Open:Play()
		script.Parent.Parent.Parent.Shop:TweenSize(UDim2.new(0.497, 0, 0.708, 0), "In", "Linear", 0.3)
		wait(0.3)
		for i,v in pairs(script.Parent.Parent.Parent.Shop.Frame:GetChildren()) do
			if v:IsA("ImageButton") then
				v.Visible = true
			end
		end
		for i,v in pairs(script.Parent.Parent.Parent.Shop.Frame:GetChildren()) do
			if v:IsA("ScrollingFrame") and v.Name == "WeaponsFrame" then
				v.Visible = true
			end
		end
		game.Lighting.Blur.Enabled = true
		game.Workspace.Camera.FieldOfView = 80
	end
end)
1 Like

show the script for the button

1 Like

Went and updated the original post.

Why are you trying to require a module when you could simply do…

local Button_One = nil
local Button_Two = nil
--ect..

Button_One.MouseEnter:Connect(function()
--code
end)

Button_One.MouseLeave:Connect(function()
--code
end)

Because this is what I did before, the module was supposed to fix it because it does some extra checks, but it doesn’t. Both methods don’t work and the result is the same.

With the script I provided, I never have any problems. Maybe have the functions load at the start of the script?

The TweenSize function has an override parameter. Have you tried setting that to true? The MouseEnter tween is probably not completed by the time the MouseLeave event is triggered and therefore does not get overridden.

1 Like

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