Gui not going back to its original place

I am using the MouseEnter/MouseLeave function on some of my GUI buttons. It will move where it should be when you move your cursor over it, but when you take your cursor away, it does not go back. Why is this happening?

1 Like

Move this post to #help-and-feedback:scripting-support; as this involves coding. We cannot help you without a sample of your code, however it is 100% due to the fact that you input an incorrect value.

Wait, but if you don’t know my code… how do you know it is 100% due to the fact that I typed it wrong?

Your code does what you tell it to, it does not have a mind of it’s own. If it is moving to a position, it is a position that you specified. Are you going to share your code with us? Also, code review is the wrong category. Move this to #help-and-feedback:scripting-support like I said.

Well, you could be a little less pushy about it. Heres my code:
local Play = script.Parent.PlayButton

local Settings = script.Parent.SettingsButton

local Changelog = script.Parent.ChangelogButton

local Gamepass = script.Parent.GamepassButton

Play.MouseEnter:Connect(function()

Play:TweenPosition(

UDim2.new(0.1, 0,0.492, 0)

)

end)

Play.MouseLeave:Connect(function()

Play:TweenPosition(

UDim2.new(0.025, 0,0.492, 0)

)

end)

Settings.MouseEnter:Connect(function()

Settings:TweenPosition(

UDim2.new(0.123, 0,0.606, 0)

)

end)

Settings.MouseLeave:Connect(function()

Settings:TweenPosition(

UDim2.new(0.048, 0,0.606, 0)

)

end)

Changelog.MouseEnter:Connect(function()

Changelog:TweenPosition(

UDim2.new(0.149, 0,0.722, 0)

)

end)

Changelog.MouseLeave:Connect(function()

Changelog:TweenPosition(

UDim2.new(0.074, 0,0.606, 0)

)

end)

Gamepass.MouseEnter:Connect(function()

Gamepass:TweenPosition(

UDim2.new(0.171, 0,0.84, 0)

)

end)

Gamepass.MouseLeave:Connect(function()

Gamepass:TweenPosition(

UDim2.new(0.096, 0,0.606, 0)

)

end)

As far as I can see, there are no errors in your code, your UI is not “going back to its original place” because a UDim2 value you specified is not the original position of the UI.

I just figured out that if I keep my cursor on it for a long period of time and then take it off, it returns to it’s original position. How can I make it so I don’t have to hover over it for a long time, and it goes back even if I don’t hover for a long time?

maybe try typing out the whole tween command

object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0),number time = 1.0, Enum easingStyle = Enum.EasingStyle.Quad, Enum easingDirection = Enum.EasingDirection.Out, number repeatCount = 0, bool reverses = false, number delayTime = 0 )
Creates a new Tweeninfo.)

more info here

Tween has a feature called delay where you can set it to 0 seconds and should run Instantly.

This is due to MouseLeave events not firing fast enough I think. I believe this is something that you can’t fix (probably) so you would need to figure out a hacky way to have the same functionality. What I did when I encoutered this problem is that I added invisible frames on the areas outside the button instead and added a MouseEnter event on it to return buttons to original position. Basically, if mouse hovers outside the buttons, it will return buttons to original position.

That makes sense, I’ll go try that.

I tried @HelpfulFLASH_KID’s and @Jerrythepancakesmith’s ideas, they didn’t work for me. How else could I get the MouseLeave event to fire faster?