How to make a gun shoot on mobile

Hi I would like to know how I make a gun shoot were ever the screen was tapped on mobile

There is an event called Tool.Activated. This event fires when a player clicks/taps on their screen while they have a tool equipped. So you should use Tool.Activated.

Code example:

local Gun = script.Parent

Gun.Activated:Connect(function() -- this works for both PC and Mobile players
    -- your code
end)

Yes, I know how to do that but how do I make it shoot where ever I pressed?

Well you’ll need to get the mouse’s position relative to the 3D environment and then use that to determine the direction of the gun’s projectile.

1 Like