Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to detect if a player is holding down the mouse button for tools?

Asked by 6 years ago

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.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question