Player has to double tap the screen to interact properly

Currently, I’m trying to create a system that will allow the player to interact with an object by touching their screen (or clicking on it with their mouse on PC.) The idea is they can only press on certain parts, and that the loading bar will appear where they pressed.

However, my problem is that detecting if they pressed on one of the certain parts and making the loading bar appear where they pressed requires two different functions; TouchTapInWorld and TouchTap respectively.

I have used both of these functions but have ran into a problem. I have to tap twice in order to make the UI appear where they pressed. This is obviously, not what I want.


(Video of the mentioned problem)

This is my first time tackling any kind of mobile support, so any help would be greatly appreciated!

Update:

I figured out I don’t have to use TouchTap at all, and can just use the position given by TouchTapInWorld. Unfortunately, the same problem still occurs where I have to double tap.

Here’s my scripting if it’d help at all:

UIS.TouchTapInWorld:Connect(function(position,processed)		
	local Target = findTargetedPart(position)
	if Target ~= nil then
		if Debounce == false then
			foundTarget(Target)
			if not processed then
				if Debounce == true then
					Moveable = false
					interactTween:Play()
				end
			end
		end
	end
	Frame.Position = UDim2.new(-Frame.Size.X.Scale/2, position.X, -Frame.Size.Y.Scale/2, position.Y)
end)

Not exactly a solution, but rather a tip:
Debug, debug, debug.print() (and breakpoints) is your friend.
Sprinkle a few print statements in there logging where we ignored an event, and what the value was to cause it to be ignored! Does TouchTapInWorld only get fired on a double tap?

Ok, now for actual help:
How are you checking debounce is both True AND False a the same time? I’m surprised it even worked at all!

Woops, I guess that’s what I get for posting my code in a rush without including my functions.

Good news is though, I don’t have to post them! I fixed it! All I did was change it from the way it was as I posted, to this:

UIS.TouchTapInWorld:Connect(function(position,processed)		
	local Target = findTargetedPart(position)
	if Target ~= nil then
		if Debounce == false then
			foundTarget(Target)
			Frame.Position = UDim2.new(-Frame.Size.X.Scale/2, position.X, -Frame.Size.Y.Scale/2, position.Y)
			if not processed then
				if Debounce == true then
					Moveable = false
					interactTween:Play()
				end
			end
		end
	end
end)

For whatever reason, all I had to do was move the line upwards. Still not sure why it didn’t work before, but at least it does now!

1 Like