How to check if UserInputService clicked is a frame

So I’m using UserInputService to give a player a currency when they click anywhere on the screen, but I don’t want to give them any if they clicked a frame, I know I probalby have to use ‘IsA’ but I don’t know how to define frame. ``Heres the code --dont mind my notes, they’re for myself for later

wait(15)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local debounce = false
local gui = player.PlayerGui
--dont mind any of this this is something else
local backpack = gui.Backpack.PackUp.Open
local fullbag = gui.FullBag.BackFrame.Main.Open
local nocoins = gui.NotEnough.BackFrame.Main.Open
local inventory = gui.Inventory.Inventory.Open
local shop = gui.ShopGui.Back.Open

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton1 or inputType == Enum.UserInputType.Touch then
	
	if gameProcessedEvent == true then
		else
			--DEBOUNCE
			if not debounce then
				debounce = true
				--FULL PACK
				if 
			if player.leaderstats.Zaps.Value == player.BackpackShop.BackpackV.Value then
				player.leaderstats.Zaps.Value = player.BackpackShop.BackpackV.Value
				backpack.Value = false
				fullbag.Value = true
				nocoins.Value = false
				inventory.Value = false
				shop.Value = false
				player.PlayerGui.FullBag.BackFrame.Main:TweenPosition(UDim2.new(0.4, 0, 0.35, 0), "Out", "Elastic", .7)
				wait(.9)
				player.PlayerGui.FullBag.BackFrame.Main.InfBag:TweenPosition(UDim2.new(0, 0,1.061, 0), "Out", "Bounce", .2)
				wait(.7)--thanks to kingerman88 for the fix (devforums)
				debounce = false
				else
				if player.leaderstats.Zaps.Value > player.BackpackShop.BackpackV.Value then
				backpack.Value = false
				fullbag.Value = true
				nocoins.Value = false
				inventory.Value = false
				shop.Value = false
				player.PlayerGui.FullBag.BackFrame.Main:TweenPosition(UDim2.new(0.4, 0, 0.35, 0), "Out", "Elastic", .7)
				wait(.9)
				player.PlayerGui.FullBag.BackFrame.Main.InfBag:TweenPosition(UDim2.new(0, 0,1.061, 0), "Out", "Bounce", .2) 
				wait(.7)
				debounce = false
					else
					
					--IF NOT FULL GIVE 
					game:GetService("ReplicatedStorage").Stats.GiveZaps:InvokeServer()
					wait(.7)--wait for debounce :D
					debounce = false
						end
					end
				end
			end
		end
	end)

If you can help please do so, Thank You :))

ContextActionService might help you here, as if you click a button when you’re using ContextActionService to detect clicks it will pick that up and not fire the input function.

local clickFunction = function(actionName, state, input)
   if state ~= Enum.UserInputState.Begin then return end
   -- do stuff
end
game:GetService("ContextActionService"):BindAction("actionName", clickFunction, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch)

Alternatively, all visible GUI objects have input events that mirror UserInputService. You can make use of this in your situation by having the clickable frame be where it needs to be, then have it covered by other GUI Objects (or whatever you like) with their Active properties set to true. Then you can do:

clickableFrame.InputBegan:Connect(function(inputObject)
   -- do stuff here
end)

InputChanged and InputEnded are also available.

1 Like

Thank you! :smiley: This helps me a lot