Detecting Mobile Player Holding Screen

Hey! I have recently been working with mobile interface but how do i check if the player is holding down the screen?

while UIS:IsKeyDown(Enum.KeyCode.E) do

UIS.InputBegan:connect(function(input,gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			local Count = 0
			local Goal = 20
			while UIS:IsKeyDown(Enum.KeyCode.E) do
				local Generator = FindClosetGenerator()
				if Generator then
					local Power = Generator.Base.Power
					LastGenerator = Generator
					if Count == Goal then
						game.ReplicatedStorage.Generator:FireServer(Generator.Name)
						Count = 0
					else
						Count = Count + 1
						local num = (Count / 400 * Goal)
						if Power then
							Power.Enabled = true
							Power.Power:TweenSize(UDim2.new(num, 0,1, 0))
						end
					end
				else
					Count = 0
				end
				wait(1)
			end
		end
	elseif input.UserInputType == Enum.UserInputType.Touch then
		print("Touch screen detected")
		print"Touch"
	end
end)

Well you would use Activated when clicking/holding on something.

You can use TouchLongPress to detect when the player is pressing down on the screen:

local UserInputService = game:GetService("UserInputService")
 
function TouchLongPress(TouchPositions, state, gameProcessedEvent)
	print("Long press event fired. State of press: "..tostring(state))
end
 
UserInputService.TouchLongPress:Connect(TouchLongPress)

you can use Enum.UserInputState.Begin to check when they first started holding down and Enum.UserInputState.End to see when they stopped

state is the current state

make sure to test on mobile though because it doesn’t work in the device emulator.

3 Likes

Uhhh Activated is an event for tools… for mobile you should use UserInputService, or use Activated for PC and then check if UserInputService.TouchEnabled is true to then connect some UserInput for mobiles.