This is a semi automatic gunfire script that works, however, I need to make it a fully automatic script, which means I need to loop it but I can't seem to figure out how to loop it correctly. What should I do to make it where the gunshots repeat until the mouse button is let up?
local MaxAmmo = 30
local Reloading = false
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local playerGui = player:WaitForChild("PlayerGui")
local TextLabel = playerGui:WaitForChild("AmmoDisplay"):FindFirstChild("AmmoText")
local Ammo = MaxAmmo
-- global reload function --
local function Reload()
Reloading = true
wait(1)
Ammo = MaxAmmo
Reloading = false
end
-- holding item, print equipped --
script.Parent.Equipped:Connect(function()
print("G36 equipped")
end)
-- click to attack --
script.Parent.Activated:Connect(function()
print("fired "..Ammo)
if Ammo > 0 and not Reloading then
Ammo -= 1
print(Ammo)
script.Parent.GunShot:Play()
workspace.Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(0.03,0,0)
wait()
workspace.Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(-0.01,0,0)
wait()
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.DealDamage:FireServer(Mouse.Target.Parent, 26)
end
elseif Reloading == false then
Reload()
script.Parent.GunShot:Stop()
end
while wait() do
TextLabel.Text = Ammo.."/"..MaxAmmo
end
end)
-- R to reload --
local Input = game:GetService("UserInputService")
Input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and Reloading == false and Ammo ~= MaxAmmo then
Reload()
end
end)
-- deactivate detect --
script.Parent.Deactivated:Connect(function()
print("Stopped Firing")
end)

1 comment
man its so much neater than mine lol. Thanks!