Help with fixing problem involving :TweenPosition()?
So, I have a Menu Gui basically with several buttons on the menu. What I want to happen is, I want the buttons to slide out when the mouse hovers over it, and go back in place when the mouse leaves the button.
However, as I have several buttons, I don't want to input the button Position for each button. I attempted to create a function to solve this, and it somewhat works. However, when it happens multiple times it starts moving off the intended location.
Here's what happens: http://i.imgur.com/aYwrnD7.gifv
If you could, please explain to me what the problem is and what I can do to fix it?
02 | local teleportService = game:GetService( "TeleportService" ) |
03 | local players = game:GetService( "Players" ) |
04 | local plr = players.LocalPlayer |
05 | local trainingPlace = nil |
08 | local trainButton = script.Parent:WaitForChild( "trainButton" ) |
09 | local rallyButton = script.Parent:WaitForChild( "rallyButton" ) |
10 | local dbButton = script.Parent:WaitForChild( "dataBaseButton" ) |
11 | local raidButton = script.Parent:WaitForChild( "raidButton" ) |
13 | function moveIn(button) |
15 | local pos = button.Position |
16 | local oldpos = button.Position |
17 | local newpos = pos + UDim 2. new(. 05 , 0 , 0 , 0 ) |
18 | button:TweenPosition( newpos, "Out" , "Quad" , . 2 , true ) |
22 | function moveOut(button) |
24 | local pos = button.Position |
25 | local oldpos = button.Position |
26 | local newpos = pos - UDim 2. new(. 05 , 0 , 0 , 0 ) |
27 | button:TweenPosition( newpos, "In" , "Quad" , . 2 , true ) |
31 | trainButton.MouseEnter:connect( function () |
35 | trainButton.MouseLeave:connect( function () |