How can I make holding LMB over UI count as a click?

Hello! Sorry if the title is unclear. I’ll try to clarify.

In my game, I have a few nonogram puzzles for the player(s) to complete (if you don’t know what those are, you should look them up). The way that it currently works is that the player has to individually click every square to change it to and from black and white. And although this works, and it’s not a massive issue because the puzzles are only 5x5, I think it would make for a better experience if the player(s) could drag click over the squares and have them all register that as a regular click and change state accordingly.

I can’t find any topics on this because it all seems to be about draggable UI (as in UI that can be dragged around the screen), which isn’t really what I’m looking for. I tried using MouseButton1Down() but that only registers on the square that you initially press it down on.

So, is there a way to make drag clicks count as regular clicks? I’m sorry if I’m missing something obvious, I’m still somewhat new to coding in Roblox.

Use the .MouseEnter event on a GuiObject if you want to detect when a mouse hovers over the GuiObject. You’ll probably need to use UserInputService to check if the mouse is being held down though.

2 Likes
local UserInputService = game:GetService("UserInputService ")
dragging = false
UserInputService.InputBegan:Connect(function(input)
      if input.KeyCode = Enum.KeyCode.MouseLeftButton then
            dragging = true
      end
end)
UserInputService.InputEnded:Connect(function(input)
      if input.KeyCode = Enum.KeyCode.MouseLeftButton then
            dragging = false
      end
end)

--do this on all the squares
square.MouseEnter:Connect(function()
      if dragging then
            print("activated")
      end
end)
1 Like

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