How to detect mouse entering surface gui buttons

Guys i really need your help. In pls donate, when your mouse moves to a donate button of each stand, there will be an info frame following the mouse until leaving the button.
I want to do the same, but i just cant find the solution.
Yes I do know that MouseEnter and MouseLeave exist, but they are for choosen buttons.
Please help me, and thank you!

1 Like

You can use the method YourButtonHere.MouseEnter:Connect(Function()
your code here)

1 Like

I know but there are so many stands and setting all of them would be very laggy

1 Like

How so, If you set it up on the client then the lag shouldnt really pop up, also it isn’t a loop it just checks for when the mouse enters the gui.

i mean the buttons are from surface gui so it will be more tricky accessing them with local script.

How will it be tricky accessing them from a local script? If the problem is putting the method for all of them you can just use a for loop to apply the method to all of them.

I mean the buttons are added by cloning, so thinking about situations drive me insane.

But you can still use a for loop to go through all the cloned buttons.

1 Like

?

Place file:
pls donate booth.rbxl (66.9 KB)

I might have an idea for you, in order to make it possibly work.

You could use something like a for loop, to loop through all the buttons to make the function be connected to them all.

1 Like

Do you mean that you want all the buttons to implement the same function (detecting if a mouse entered the gui) from one script?

Here’s a solution you can try:

  1. Create a script in the same parent object as your surface GUI buttons.
  2. In the script, use the GetGuiObjectsAtPosition function to detect if the mouse is hovering over any surface GUI button.
  3. If the mouse is hovering over a button, create and position an info frame at the mouse’s current position.
  4. Update the position of the info frame as the mouse moves.
  5. Remove the info frame when the mouse leaves the button.
local Players = game:GetService("Players")
local Mouse = Players.LocalPlayer:GetMouse()

local infoFrame = nil

Mouse.Move:Connect(function()
    local guiObjects = Mouse:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y)
    
    for _, obj in ipairs(guiObjects) do
        if obj:IsA("TextButton") and obj.Parent.Name == "YourButtonParent" then
            if not infoFrame then
                infoFrame = Instance.new("Frame")
                infoFrame.Size = UDim2.new(0, 100, 0, 50)
                infoFrame.BackgroundColor3 = Color3.new(1, 1, 1)
                infoFrame.BorderSizePixel = 0
                infoFrame.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
                infoFrame.Parent = game.Players.LocalPlayer.PlayerGui
            end
            break
        end
    end
    
    if not infoFrame then
        infoFrame:Destroy()
        infoFrame = nil
    end
end)

yes.
sfkadfakfkdfsdkadfsaafsddfasfasd

1 Like

I can help you with that actually.

Now tell me … Are all the buttons stored under one instance? Or are they stored in different instances?

Guys I already found a solution by myself, it was easier than I thought.

I make a function that adds MouseEnter to each button
And call that function everytime character respawns or someone’s stand is created

1 Like

Have you created a LocalScript for every button ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.