I am making a clicker game as a project, and I want to make it so when I click on a button it won’t count as a click (like so player doesn’t get the currency he gets for clicking)? robloxapp-20240424-2010396.wmv (3.6 MB)
I got no idea how to know if the player is clicking on something that is not a Gui button.
This is the code I use for this part of the script:
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType Enum.UserInputType.Touch then
print("Add money")
end
end)
Should I maybe make a button that is the whole screen instead of this? I tried the button but it made it so I cant rotate my camera anymore and for mobile it had other problems.
local UIS=game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
if not gameProcessedEvent then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Add money")
end
end
end)
This is made to do this, but the other way around. So we can just use a not.
Basically saying: Is the mouse NOT over a Gui item…
You don’t need to say “gameProcessedEvent” … but that is what the 2nd parameter is.
If you want a button to not receive click events, disable the GuiButton’s Active property. What are you intending to accomplish with tracking clicks that weren’t on a button?
i want the player to not get money when clicking if he clicks on a button. for example he opens the chat or he opens the shop. i want him to get money when he clicks on the screen or the button made for clicking.
You can use :GetGuiObjectsAtPosition() to figure out whether or not the mouse is currently over a gui object (such as a button)
example:
local localplayer = game.Players.LocalPlayer
local mouse = localplayer:GetMouse()
mouse.Button1Down:Connect(function()
local guiobjects = localplayer.PlayerGui:GetGuiObjectsAtPosition(mouse.X, mouse.Y)
if #guiobjects == 0 then -- not over any gui object
-- increment clicker count
end
end)
I just posted the real way you do that… Test it out (I did).
This is used so you can click a Gui item and not set off a click function someplace else.
I simply turned it around to test if you are not over a Gui item. Pretty straight forward stuff.