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

How do u tween a textbutton's size so it looks like it expanded in all directions? [REPOSTED]

I'm trying to do so when you hover your mouse over a textbuttons it tweens it's size to expand in all directions, but kinda just expands to it's left and below. This is the script:

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(UDim2.new(0,250,0,100),"Out", "Bounce")
end)
script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(UDim2.new(0,200,0,50),"Out", "Bounce")
end)

Obviously, I need to change the numbers in between the brackets, but I don't know what numbers should I use. (After repost) I tried these methods from answers: Tween the size and the position at the same time, change anchor point to the centre, and the last I didn't really understand, so I'm just going to copy the answer here: "Make the y size cover all the screen then you just need to change the y size (with textscaled on).. that's how i do it, it kinda move up and down (and it's at the middle)"

1 answer

✓ Accepted answer

You have to set the AnchorPoint of the gui to 0.5, 0.5 (not inside the script). The gui should then expand in all directions.

Keep in mind that changing the AnchorPoint will also reposition the gui. Just minus off half the gui's size from the gui's position and it will return to its normal position. e.g. if the size was UDim2.new(0.3, 0, 0.2, 0) and the position was UDim2.new(0.5, 0, 0.4, 0), once you change AnchorPoint to 0.5, 0.5, the position should be UDim2.new(0.5 - (0.3 / 2), 0, 0.4 - (0.2 / 2), 0) = UDim2.new(0.35, 0, 0.3)

However I notice that your gui's size is using offset. I suggest you use scale instead, so that the size is consistent throughout different devices.

If you don't know what scale and offset is, scale is the first and third number, and offset is the second and fourth number in a gui's .Size and .Position property: UDim2.new(xScale, xOffset, yScale, yOffset. What scale does is it sizes based on a percentage of the gui's parent. What offset does is it sizes based on pixels. So on different screen sizes scale would make your gui look more consistent.

Here's a wiki link on GUIs if you're still confused: https://developer.roblox.com/en-us/articles/Intro-to-GUIs

1 comment

0

Thank you!

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