Hold-To-Use Tool For Mobile?

I have a Scanning and Extracting tool that on .Activated, until deactivated, spawns raycasts and a beam towards wherever the player’s mouse is. The attachment the beam projects towards is positioned where the raycast hits if it hits.

How do I make this mobile-compatible so you have to hold the area your scanning in order for it to succesfully scan? So far nothing happens, as expected, because holding down moves the camera.

My activation/deactivation code is:

local mouse = game.Players.LocalPlayer:GetMouse()
local joe = false                                               --Not holding

	joe = true                                                  --Holding
	while joe == true do --Fire scanning event while holding
		script.Parent.Fire:FireServer(mouse.Hit.Position)       --Tell event they're holding

	joe = false                              --No longer holding
	script.Parent.Fire:FireServer()          --Tells event they aint holding

Apparantly I should be using UserInputService instead of mouse but even then I’m unsure how to make it mobile compatible.

It must be possible because a game I played used to be available on mobile and although was removed, wouldn’t have been available in the first place because the game would be unplayable without their scanner, unless it simply had different mechanics on mobile.

1 Like

This isn’t the best solution, but you could make the raycast come from the players camera and whitelist their character. If you want, you could also force the player to go in first person if they’re on mobile.

Are you trying to make it so players on mobile are able to pick up tools by “Press and Hold”?

If so, then you should use a proximity prompt for it. You can directly decide if you to do “Press and Hold” to pick up the tool in the Properties. You can also choose the amount of seconds with the Properties.

Put the Proximity Prompt under the handle of the tool, then create a script for it.

I hope this helps :slight_smile:

Please correct me if I’m wrong, because I don’t have much experience with scripting. :sweat_smile: