Is there an event for when a player on a touch device clicks on the world, and not a GUI object?

Hey there!

I am creating a game with a building system, and the player needs to tap on the world to choose where they want to place a building, and then click on a GUI button to actually place it. The main problem is that the building updates when I click on the button. After some searching, I found that the only suitable event documented is TouchTapInWorld, which states that it won’t fire when the player taps on a GUI element. However, it fires when I tap on a GUI element. Is there a workaround for this?

This is the code I am using:

userInputService.TouchTapInWorld:Connect(function()
	print("Mobile Tap In World")
	updatePosition()
end)

Here’s a video of me demonstrating the problem:

You can use UserInputService.InputBegan and it’s parameters.

--processed will be false if tapped in world
UserInputService.InputBegan:Connect(function(input: InputObject, processed: boolean)
    if (input.UserInputType == Enum.UserInputType.Touch) and (not processed) then
        --to get the position of where they tapped, you can cast a ray from the mouse's current position.
        --The mouse for mobile players goes to the last place they tapped, note this may not work in test mode.
    end
end)
1 Like

It works! Thank you so much.

This is the code I used:

userInputService.InputBegan:Connect(function(input, gameProcessed)
	if (input.UserInputType == Enum.UserInputType.Touch) and (not gameProcessed) then
		print("Updated Position")
		updatePosition()
	end
end)
1 Like