Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does the GUI go to the top of the screen?

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!

4 comments

0

try setting offset(first numver in you udim2.new) to 0

0

its definetly the way you have youre numbers set up

0

can you give me the position of the guis (labeled please)

0

Credits: {0.5, -50},{0.5, 25} Play: {0.5, -50},{0.5, -50}

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.