I'm trying to make a main menu type GUI and I want the buttons to tween to the right a little when your mouse hovers over them and then to go back when the mouse leaves. For some reason when your mouse hovers over the button the GUI tweens to the top of the screen. Here is the code:
function me(button) button.MouseEnter:connect(function() button:TweenPosition(UDim2.new(0.5, 0,button.Position.Y), "Out", "Quad", 3, true) end) button.MouseLeave:connect(function() button:TweenPosition(UDim2.new(0.5, -50,button.Position.Y), "Out", "Quad", 3, true) end) end me(script.Parent.Credits) me(script.Parent.Play)
NOTE: I'm very new to Udmi2 and tweening. Thanks!
The TweenPosition()
function called on lines 3 and 6 have a couple of issues:
There is no offset on the Y-Scale listed.
The proper format for a UDim2.new() function looks like this: UDim2.new(xScale,xOffset,yScale,yOffset)
. To fix the first issue in the script, change both lines 3 and 6 to this:
button:TweenPosition(UDim2.new(0.5,0,button.Position.Y,0),"Out","Quad",3,true) --and button:TweenPosition(UDim2.new(0.5,-50,button.Position.Y,0),"Out","Quad",3,true)
Now for the second issue:
The button.Position.Y property is actually two properties.
button.Position.Y
contains two values, the scale and offset. The proper property for the button's Y-Scale is button.Position.Y.Scale
. The final versions of lines 3 and 6 should look like this:
button:TweenPosition(UDim2.new(0.5,0,button.Position.Y.Scale,0),"Out","Quad",3,true) --and button:TweenPosition(UDim2.new(0.5,-50,button.Position.Y.Scale,0),"Out","Quad",3,true)
For more information, read up on UDim2.new()
and TweenPosition()
here and here. I hope this helped!