Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with fixing problem involving :TweenPosition()?

Asked by 8 years ago

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?

01--//Variables
02local teleportService = game:GetService("TeleportService")
03local players = game:GetService("Players")
04local plr = players.LocalPlayer
05local trainingPlace = nil
06local rallyPlace = nil
07local rclPlace = nil
08local trainButton = script.Parent:WaitForChild("trainButton")
09local rallyButton = script.Parent:WaitForChild("rallyButton")
10local dbButton = script.Parent:WaitForChild("dataBaseButton")
11local raidButton = script.Parent:WaitForChild("raidButton")
12 
13function moveIn(button)
14 
15    local pos = button.Position
View all 37 lines...

1 answer

Log in to vote
1
Answered by 8 years ago

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

0
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 . SketchTitan 40 — 8y
0
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. SwardGames 325 — 8y
Ad

Answer this question