What do you want to achieve? Im trying to make a Circle UI Button
What is the issue? The issue im having is that the hitbox of the UI is not a circle so the player can click the button even tho the mouse is outside the circle
What solutions have you tried so far? I have looked a lot for days on everything (devforum, Discord helps, yt videos) but still couldn’t figure out how to make a custom circle hitbox
I think it can be made by some math on the mouse position but im not that good at math.
I already have a UI circle from an imagelabel.
The issue im having is that that player can press the button even tho the mouse is outside the “circle” imagelabel because of the image button hitbox.
Not possible. Unless your willing to map out individual pixels of said button which is just a headache to do then there is no chance you can achieve it.
(One way I though is using distance. As we know a circle have a constant radii so if you can just use a loop and see if the mouse is within said radii.)
Make your own custom text button clicked code. Every time you click the button, check if the distance between the position of the circle and the position of the mouse is less than the radius of the circle. If it is, then you know they clicked
My issue is with the button its self. You see when you select the gui there is a “hitbox” its an outline for the ui and its the button hitbox so when you click anywhere inside it it will trigger the mouse click function.
local button = -- path to button
local absolutesize,absoluteposition = button.AbsoluteSize,button.AbsolutePosition
local radii = absolutesizeMagnitude/2
local runservice,userinputservice = game:GetService("RunService"),game:GetService("UserInputService")
runservice.RenderStepped:Connect(function()
if (userinputservice:GetMouseLocation()-absoluteposition).Magnitude <= radii then
-- do whatever you want smh.
end
end)
I think i figured out why was my math wrong. Cuz i used half of the imagebutton X Size as a radius for the circle but its wrong cuz the imagebutton still not a circle. Now i need to know what is exactly the radius of the circle.