Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How would I make this MouseEnter//Leave function not get stuck and not Leave?

Asked by
unmiss 337 Moderation Voter
9 years ago

My current code:

function HoverOn()
script.Parent:TweenPosition(UDim2.new(0,5,0,0), "In", "Sine", 0.1)
end


function HoverOff()
script.Parent:TweenPosition(UDim2.new(0,0,0,0), "Out", "Sine", 0.1) 
end

script.Parent.MouseEnter:connect(HoverOn)
script.Parent.MouseLeave:connect(HoverOff)

Explanation: It works okay, but when you quickly move your mouse off of it, it doesn't trigger the MouseLeave. It's like a selection notifier, hard to explain. It just makes the GUIs look fancy.

Example: http://i.imgur.com/jZJQEhH.gif

See the ones still sticking out, and the MouseLeave event clearly wasn't fast enough to trigger? I don't want that happening. It also seems like clicking on it completely screws up the MouseLeave as well.

Any solutions?

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

If you look at the wiki page for TweenPosition, you'll notice another argument that you didn't include when you called it in your code. This argument is override. It determines whether the the tween can be overridden by another tween. Since you didn't include it, it will default to false, i.e., you will not be able to start a new tween until the first tween is finished.

I believe this is your problem. When you move your mouse quickly, the MouseLeave event does fire, but the first tween is still happening, and it can't be overridden. This means It just finishes, then stops. I believe you can fix this just by setting the override argument to true.

script.Parent:TweenPosition(UDim2.new(0,5,0,0), "In", "Sine", 0.1, true)
0
PERFECTO, THANK YOU!!! unmiss 337 — 9y
Ad

Answer this question