Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Are mouse-related events regarding GUI instances broken in plugins?

Asked by 8 years ago

I'm currently making an anti-virus plugin, and I tried implementing a hint system (where a gui would display text when you hover over a gui button and track the mouse). Although, I realised soon after that this was not acting like I would have expected it to act in a normal server.

Firstly:

I am using the MouseEnter, MouseLeave and MouseMoved events on the GUI instances, then moving them to a position using the mouse's X and Y coordinates.

This is an example code (I couldn't be bothered to get it, lol):

Gui.MouseEnter:connect(function()
    Hint.Text = "Hm"
    Hint.Size = UDim2.new(0, Hint.TextBounds.X, 0, 16)
    Hint.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
    Hint.Visible = true
end)

Gui.MouseMoved:connect(function()
    Hint.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
    Hint.Visible = true
end)

Gui.MouseLeave:connect(function()
    Hint.Visible = false
end)

And before you ask, I have already:

  • Assigned the variable "Mouse"
  • Activated the plugin
  • Set the GuiPart's Active value to true

Here is a GIF of the problem that I had:

GIF link

(First number = Mouse.X, Second number = Mouse.Y)

The same X,Y coordinates were being recorded from the MouseEnter, MouseMoved and MouseLeave events... And yes, I did move the mouse...

So, anyone got any ideas to fix/bypass this problem?

(If anyone's REALLY interested, then here's the Plugin

1 answer

Log in to vote
1
Answered by 8 years ago

I assume you're using the this Mouse object (or the PluginMouse, which apparently works the same). My guess is that it doesn't update its coordinates when its over a GUI.

Fortunately, both MouseEnter and MouseMove provide x and y coordinates as coordinates, so you can use those instead of Mouse.X and Mouse.Y.

If that doesn't work, I'd recommend trying InputBegan, InputChanged, and InputEnded (to replace MouseEnter, MouseMove, and MouseLeave, respectively). You may wish to ignore certain types of input (ex just listen to MouseMovement )

0
Thank you, I considered that, but doesn't the X and Y co-ords for the events return the offset in relation to the button itself, rather than the global position (so the hint textlabel would have to be in the same frame as the button)? darkelementallord 686 — 8y
0
No, they return absolute coordinates chess123mate 5873 — 8y
Ad

Answer this question