I was making a projectile gun, and I am having trouble with the shooting. It works fine, but I want to make it only shoot once when clicking once, then holding down shoot multiple times. Any advice on how to do that? My script:
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local barrel = tool:WaitForChild("Barrel")
local cas = game:GetService("ContextActionService")
local rs = game:GetService("ReplicatedStorage")
local fire = false
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
function shoot(actionName, inputstate)
if inputstate == Enum.UserInputState.Begin then
fire = true
end
if inputstate == Enum.UserInputState.End then
fire = false
end
end
function bullet()
rs:WaitForChild("GunEvent"):FireServer(tool, barrel.Position, mouse.Hit.p)
wait(0.5)
end
cas:BindAction("Shoot", shoot, true, Enum.UserInputType.MouseButton1,
Enum.UserInputType.Gamepad1)
game:GetService("RunService").RenderStepped:Connect(function()
if fire == true then
bullet()
end
end)
(There is other scripts connected to it to make it work, I'm not sure if I need to send them).

4 comments
Yes, ik. When the player lets go of their mouse, isfiring = false, so it stops shooting.
No but, thing is., yes your code is a good method, but aswell I want to try experiment with clicking guns. What you just said works with my gun fine, but the problem I am having is, If the player holds the button down, it will fire rapidly, if the player only clicks, it will fire only 1 bullet or so.
Add a wait in your shoot function.
I tried that, with the bullet function- shoot function would just make the bullets go slower. That's not what I am attempting to do.