✓ Accepted answer
Mouse.Button1Down only fires once. If you want the code to run multiple times, you'll need a loop of some sort. You'll also need to capture when the player stops holding down the button. Here is a quick example of this:
local depressed
Mouse.Button1Down:Connect(function()
if equipped then
depressed = true
while depressed and equipped do
wait(.2)
end
end
end)
Mouse.Button1Up:Connect(function()
depressed = false
end)
This is just a quick example. You can get the same functionality with tool.activated and tool.deactivated as well. Be careful if you attempt to set a cooldown that's verified from the server as there can be time differences because of lag and the local time of the client probably won't match the local time of the server. A good way to get around this is using some sort of time sync service. There is one included in Nevermore by Quenty: Nevermore.
Nevermore is a HUGE library that contains a lot of helpful modules. I highly suggest learning more about it and at the very least you can use it to learn how Quenty solved certain problems.
[EDIT] To make the script stop shooting after it runs out of bullets, you'll need to add a check for that as well. You can do this check on the while loop line, or directly after (doesn't really matter). Here's an edit to the example above:
while depressed and equipped and bullets > 0 do
wait(.2)
end
Same code as above just written out differently:
while depressed and equipped do
if bullets > 0 then
end
wait(.2)
end
5 comments
Thanks! But my reloading thing isn't working is there a way that I can make it so when it hits zero it stops working?
elseif Ammo.Value <= 0 then Shootable = false depressed = false print("Reloading") wait(2) depressed = true Shootable = true Ammo.Value = 35
thats the script
I updated the answer
thanks! It helps a lot