So I’ve got this very basic setup that tweens a gui when the mouse enters it, it then tweens again if the mouse leaves which works fine BUT if i mouse onto and remove the mouse to fast, the GUI gets stuck after the first tweet… How do I check to see if the mouse is still on the GUI and if not, to then run the second tweet?
local object = script.Parent
object.AnchorPoint = Vector2.new(0, 0)
object.Position = UDim2.new(0.908, 0, 0.852, 0)
object.MouseEnter:connect(function()
object:TweenPosition(UDim2.new(0.858, 0, 0.752, 0), nil, nil, 1)
end)
object.MouseLeave:connect(function()
object:TweenPosition(UDim2.new(0.908, 0, 0.852, 0), nil, nil, 1)
end)
2 Likes
This is more of an issue on Roblox’s side.
I do not recommend the use of MouseEnter and MouseLeave as they aren’t as responsive. Instead, check for InputBegan and InputEnded on the GUI object and check if the input is a mouse movement.
The other issue with your script is that you need to make sure that your tween can override already running tweens by adding another parameter to your tween function.
Here is your script below:
local object = script.Parent
object.AnchorPoint = Vector2.new(0, 0)
object.Position = UDim2.new(0.908, 0, 0.852, 0)
object.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
object:TweenPosition(UDim2.new(0.858, 0, 0.752, 0), nil, nil, 1, true)
end
end)
object.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
object:TweenPosition(UDim2.new(0.908, 0, 0.852, 0), nil, nil, 1, true)
end
end)
fantastic works really well! thankyou for explaining what I had wrong
1 Like