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?
--//Variables local teleportService = game:GetService("TeleportService") local players = game:GetService("Players") local plr = players.LocalPlayer local trainingPlace = nil local rallyPlace = nil local rclPlace = nil local trainButton = script.Parent:WaitForChild("trainButton") local rallyButton = script.Parent:WaitForChild("rallyButton") local dbButton = script.Parent:WaitForChild("dataBaseButton") local raidButton = script.Parent:WaitForChild("raidButton") function moveIn(button) local pos = button.Position local oldpos = button.Position local newpos = pos + UDim2.new(.05,0,0,0) button:TweenPosition( newpos, "Out", "Quad", .2, true) end function moveOut(button) local pos = button.Position local oldpos = button.Position local newpos = pos - UDim2.new(.05,0,0,0) button:TweenPosition( newpos, "In", "Quad", .2, true) end trainButton.MouseEnter:connect(function() moveIn(trainButton) end) trainButton.MouseLeave:connect(function() moveOut(trainButton) end)
The problem is that you are adding on to the current position when tweening.
Instead, tween to predefined locations. At the top of the script, set local defaultPosition = button.Position
and local hoverPosition = defaultPosition + UDim2.new(0.5, 0, 0, 0)
and then tween to defaultPosition
in moveOut and hoverPosition
in moveIn