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)

2 comments
Aye, this works, but I have multiple buttons. I was trying to avoid writing variables for all the button's position and have it done in a function .
That is why it is based on the buttons default position. The script should be reusable, either with completely new scripts or in a for loop.