How do I make gui buttons activate when mouse is dragged over

I need the buttons to fire when the player’s mouse goes over them. I tried using:

button.InputBegan:Connect(function()
    if mouse.MouseButton1Down then
        --Code here
    end
end)

but It doesn’t update whether the mousebutton one is down or not when its over a gui button. I think its a similar thing to using gameprocessed in User Input Service, but I just cannot think of anyway to fix it, or any other workarounds. Please help

1 Like

Something like MouseEnter?
GuiObject | Documentation - Roblox Creator Hub

2 Likes

Like @Scottifly said, you can use MouseEnter and MouseLeave. These are generally used to make hover effects, too.

local function onMouseEnter()
    print("Mouse entered.")
end

local function onMouseLeave()
    print("Mouse left.")
end

button.MouseEnter:Connect(onMouseEnter)
button.MouseLeave:Connect(onMouseLeave)
3 Likes

Wouldn’t that fire when the player’s mouse just enters, regardless of whether or not their mousebutton1 was down

Yes, but you did say:

Which is what I interpreted it as, my bad.

If you want to only do things on MouseEnter if the MouseButton1 is down, you can pair it with the UserInputService’s IsMouseButtonPressed function.

2 Likes

Sorry for the poor wording, thank you so much

1 Like

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