What is the best way to make a mouse.Button1Down function for mobile?

I am making a bow which requires you to hold down your mouse button to charge up your shot, which gets fired upon release. How would I do something like this on mobile? It only works with an actual mouse at the moment

Edit: Just realised it does work with the original method I was using with mouse.Button1Down, except it still activates while moving the thumbstick or rotating the camera

2 Likes

You would have to make a UI button that is shown on mobile and detect when the button is pressed down.

This previous discussion on the forums might help:

1 Like

Have you tried using the TouchLongPress or TouchStarted events?

1 Like

or maybe UserInputService.TouchTap?

To check if a player is on mobile you could use UserInputService.TouchEnabled, then you could either use UserInputService.TouchLongPress or UserInputService.TouchStarted and UserInputService.TouchEnded to detect when a player holds tap for a few seconds or to detect when a player starts tapping and ends the tap. I’m pretty sure with this it would work.

You just answered yourself

local Players = game:GetService("Players") 
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse() 

Mouse.Button1Down:Connect(function() 
print("Hey I am held down") 
end) 

Mouse.Button1Up:Connect(function() 
print("Hey I am not held down anymore") 
end) 

Needs to be in LocalScript.

(And yeah it is working for mobiles too.)

It isn’t working for mobile. That’s what I already had but on mobile it doesn’t do anything

Would this work if I made the GUI transparent and fit the entire screen? It still needs the mouse position to know where to shoot the arrow. I tried using UserInputService.TouchStarted but that enables it regardless of whether the user is also using the mobile interface GUI or rotating the screen

edit: nevermind it was using mouse.Button1Down when it was doing that

It does work? I tested it for myself and this method works.

1 Like

Huh, sorry about that. I could have sworn it didn’t work earlier. I just tried it again and it did work this time. Any idea how I would make it so touching the thumbstick or rotating the screen doesn’t activate it?

Hm you would need to use UserInputServices tbh I dont really know how would I go about it.

you could is TouchStarted,TouchEnded,TouchMoved,TouchTap,TouchLongPress to get what you want

OP needs to get rid of Button1Down input when you are “walking” with thumbstick etc.