I am trying to make a machine gun and I want to be able for the user of my gun to hold down their mouse button instead of rapidly clicking the button. I have looked this question up, but couldn't quite find a question like mine. How would I make a function like this because the regular functions for a tool didn't seem to work for what I want.
✓ ANSWER ACCEPTED
How to detect if a player is holding down the mouse button for tools?
1 answer
✓ Accepted answer
Use the tool.Equipped event for when they equip the tool. Then use the mouseDown event instead of the mouseClick.
Im not coding or nothing so don't do this exactly, I'm just explaining.
tool.equipped
mouseDown
stop = false
repeat
shoot()
wait(1) --Time In-between the shots
until stop == true
mouseUp
stop == true
end
end
function shoot()
-- the script that shoots the gun, like what happens when the gun is shot once
end
So how this works is when the tool is equipped and the player is holding the mouse down, it will do the function shoot until the player releases the mouse. Whatever script you use for clicking and firing, you put in the shoot, apart from the event.
This discussion is preserved as it was. New answers, comments, and votes are closed.
