Shooting system problem

Hello! I’m trying to make a shooting system. I added mobile support, but with UserInputType Touch, when I rotate the camera, it shoots. I don’t want complex systems, just a simple game.

My code is:

(...)

local function shoot()
	(...)
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch and not gameProcessedEvent and equipped and tool.Enabled then
		shoot()
	end
end)

tool.Unequipped:Connect(function()
	mouse.Icon = offIcon
	equipped = false
end)

tool.Equipped:Connect(function()
	mouse.Icon = onIcon
	equipped = true
end)

You might want to use the .TouchedTap event of userInputService

UserInputService.TouchTap:Connect(function(touchPositions, GPE)

       -- Do shoot()

end)
3 Likes

thanks! but when I try to walk and shoot it shoots where I’m dragging

1 Like

Idea: Listen for when the user begins touch and ends touch. Only shoot if they let go quickly, maybe 0.4s

1 Like

thank so much! this worked! thanks for the idea

2 Likes

Theres also another variation, its functionality is similar. Personally I’ve found it a bit inaccurate, but it’s worth a try:

UserInputService.TouchTapInWorld:Connect(function(position, processedByUi)
    -- Do here shoot(), ignore if processed by UI
end)
1 Like

“thanks! but when I try to walk and shoot it shoots where I’m dragging” same problem

1 Like

yeah the second one I’ve found to be equally inaccurate. glad you found your solution!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.