.MouseLeave property failing sometimes

Hello everyone,

Quick question, is there a way to make part.MouseLeave more precise?

The code works fine for slowly moving, but when the player moves quickly over the UI element, it gets stuck open.

Here is a video for more explanation.


(On another note, why doesn’t the DevForum allow playback from WMV when Roblox literally exports captures in that type?)
Also, here is the script

local frame = script.Parent -- Reference to the Frame instance
local hover = script.Parent:FindFirstChild("Hover") -- Reference to the Frame instance
local Bar = script.Parent:FindFirstChild("Frame")

--Tween info here (works, not relevant to this)


local function onMouseHover()
	wait(0.15)
	tweenHover:Play()
	tweenHover2:Play()
	
end

local function onMouseUnhover()
	wait(0)
	tweenUnhover:Play()
	tweenUnhover2:Play()
end

-- Connect the mouse hover and unhover events to the frame
hover.MouseEnter:Connect(onMouseHover)
hover.MouseLeave:Connect(onMouseUnhover)

Does anybody have thoughts on this? The only Idea I came up with was a while loop that is checking for the mouse leaving while the player hovers.

Thanks for your time!

Okay - I’m pretty positive it has to do with that wait(0.15).

You haven’t shown your TweenInfo, however I’m assuming that the MouseEnter tween isn’t completing before that wait has finished. Therefore, when you move your mouse rapidly through the ui element, the TweenHover overrides TweenUnhover, not allowing TweenUnhover to take place. ( leaving it stuck ) even though .MouseLeave was fired.

Why is there that wait(0.15)? Perhaps remove it and see if you can still recreate this issue. If you can’t, you found your problem.

2 Likes

Thank you, you’re right, that makes total sense.

The purpose of the wait() was to stop the menu from coming up if the mouse was going over it quickly. Do you know what I should use to wait a second, check if the mouse is still there, and proceed from there?

local function onMouseHover()
	wait(0.15)
	If "mouse is still hovering" == true then
		tweenHover:Play()
		tweenHover2:Play()
	else 
		onMouseUnhover()
	end

end

What would I do for the “mouse is still hovering” part?

Thanks so much for your help!

If there’s no waits within these MouseEnter and MouseLeave events, the effect of a mouse going quickly over that UI is quite negligible. Tween’s won’t begin at the end of the prior tween, rather they’ll begin wherever they currently are. So it’ll only have to tween from current position to ‘goal position ( unhoverTween)’, and that’s only like 0.0142 seconds of distance if swiped quickly.

You want to prevent that 0.0142 seconds of distance ‘blip’, am I correct?

2 Likes

Yeah, it’s more of a superficial thing. It bothers me is the main point, I shouldn’t be getting caught up in these little things before I make most of the big stuff.

Anyway, you saying “Tween’s won’t begin…” reminded me that the tweenInfo has a delay parameter. I put the delay in at 0.1 seconds and it works just as I intended.

local tweenInfo = TweenInfo.new(
    0.2, -- Time
    Enum.EasingStyle.Quad, -- Easing style
    Enum.EasingDirection.InOut, -- Easing direction
    0, -- Repeat count (0 = no repeat)
    false, -- Reverses (true = tween back and forth)
    0.1 -- Delay time
)

Again, Thanks for your help!

2 Likes

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