Currently need a solution on how to make my mouseleave responses EVERYTIME i leave the button with my mouse. Basically a smooth transition.
1 Like
Could you provide us a script or example?
try doing this:
local Button = --put button here
Button.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
--do the mouse enter effect
end
end)
Button.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
--do the mouse leave effect
end
end)
Don’t do this. Don’t connect your ended event inside your begin event. You’re going to spawn up several idle connections each time a player hovers which is going to be very bad. Memory leaks, bad practice and performance problems to ensue.
Instead, what you can do is either separate the two events from each other or use InputChanged. Two events is probably easier to work with at a negligible cost compared to one.
Button.InputBegan:Connect(function (inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
-- _hoverEffect
elseif inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
-- _clickCode
end
end)
Button.InputEnded:Connect(function (inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
-- _leaveEffect
end
end)
-- Also:
Button.InputChanged:Connect(function (inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
if inputObject.UserInputState == Enum.UserInputState.Begin then
-- _hoverEffect
else
-- _leaveEffect
end
end
end)
3 Likes
I found a Module which might be some use to you:
My bad, I screwed up all the enums. Anything that is only Enum.Mouse
, add Enum.UserInputType
. I will fix the code sample up right now to reflect those changes.
1 Like