How can I make a hold to shoot system?


I was wondering how could I make a hold to shoot system. So it shoots the gun as long as you are holding the click button.

Can anyone help?

Is this for mobile or PC?

1 Like


character limit uzbuGBtgirguighizuhz

Maybe these could help -

1 Like

You can use UIS ( User Input Service ) to check if a player is holding down a key, and then make it process something.

Use UserInputService 's InputBegan and InputEnded events and set a boolean variable to either true or false.
In addition, you can use ContexActionService .

local Tool = script.Parent

local Toggle

local function OnActivated()
	Toggle = false
	while true do
		if Toggle then break end
		print("Hello world!")
		task.wait(1) --Gun's fire delay.

local function OnDeactivated()
	Toggle = true


You can utilize a tool’s activated & deactivated events to achieve this.

1 Like

Remember to only use loops in localscripts as serversided scripts can cause slight performance issues

you can do like

local firing = false

while (firing) do
   -- put your shooting code here

This just isn’t true, a for/while/repeat construct is far more performant than a RemoteEvent/RemoteFunction.

1 Like

Ah sorry for the misleading. Someone told me that and I just assumed it was true because of the nature of loops

I managed to make it work on PC but when I use the same gun on mobile I have to continuously tap instead of just tap and hold.