Help with logic for button animation/splash effect

Hi, so I’m trying to make simple button animations where like, you click a button, and a circle object appears, slowly fading out while increasing in size. It also originally positions based on where you click on the button.

I’m struggling figuring out how to get the position for it to appear correctly though. Here’s the code I’m using to position the circle object:

local min_x, max_x = button.AbsolutePosition.X, button.AbsolutePosition.X + button.AbsoluteSize.X
local min_y, max_y = button.AbsolutePosition.Y, button.AbsolutePosition.Y + button.AbsoluteSize.Y
local x_value = math.clamp(mouse.X, min_x, max_x)
circle.Position = UDim2.new(0, 0, 0, 0) --What value to input for X scaled??

Basically, I’m trying to get it so it grabs the mouse’s X position in offset, compares it with the size of the button, then returns a number from 0-1 and I could use that as the Scaled X coordinate of the circle’s position. However, I’ve tried different logic but the circle always appears past, or close, to 1. The end goal would be to have it position anywhere from 0-1, so if I click on the far right side of the button, it appears at 0. Far left side, 1.

I can clarify more if needed, thanks!

1 Like

Finally figured it out!

If anyone’s curious, I came up with the following idea:

I subtracted the max X size of the button (absolute X + absolute X size) from the mouse’s onscreen X position, got the absolute value of that, then divided that value by the button’s absolute X size. That gave me a value I could actually use. From there, I was able to tinker with it and divide it to get a value approximately anywhere from 0-1 so I can use Scaled.

:slight_smile:

3 Likes