Help with my GUI script!

Hi! I am creating these animated GUI buttons.

There is an issue though. Sometimes, it thinks that the mouse is NOT touching the button, when it clearly is. Here is my scripts for the buttons:

Is there a better way of going about this so that it is always correct and knows if the mouse is touching the button?

Thanks,
Harry.

3 Likes

Yes and that would be doing the players mouse here is an example for this

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

print(Mouse.X, Mouse.Y)

-- GUI pos compare
if GUI.YOUR_BUTTON_NAME_HERE.Position == Mouse.Position then
  --.. code
end

This code shouldn’t work.
With this code, the pointing device will not work until it is exactly at the center of the button.

2 Likes

Hello, you can make use of the GetGuiObjectsAtPosition to get the GuiObjects on a certain position.(you will need to use the Mouse (to get the position))

example

Perhaps you could try adding a debounce or check if the “mover” gui object is already at that specific position, if the gui is at that position, you can just return and end the event.

That’s a very bad way of handling it, the code checks if the mouse is precisely at that position, the code wouldn’t work reliably across multiple different computers as every monitor isn’t the same so the gui would just tween when a user didn’t intend to.

2 Likes