Click detection for non-button GUI elements

I’m trying to make a placement system for my game. Where if you click on an item in the inventory-gui. It places the item that you selected.

This is the ui:
image

The problem is, these ‘items’ are parts that you can pick up. And in the inventory-gui i’m displaying the parts you picked up with a ViewportFrame, their doesn’t exist a “button version” of this GUI element so my question is: How would i detect if the player clicks on the viewportframe. I don’t think an invisible button would work because it would obstruct some functionality of the viewportframe.

Does somebody have an idea as to how to solve this? Thanks

You can use GuiObject.InputBegan. The event fires when the user starts interacting with the GuiObject.

local viewportFrame = script.Parent

viewportFrame.InputBegan:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Mouse clicked")
	end
end)
2 Likes

Thanks for the help i will try it :slight_smile: