I have a gun and it works fine but you have to spam click it for the automatic weapons, I’ve attempted to make it automatic but it didn’t work too well.
(this isn’t all the code btw)
script.Parent.Activated:Connect(function()
-- Automatic
if automatic == true then
repeat wait()
if ammo > 0 and not reloading then
script.Parent.GunShot:Stop()
ammo = ammo - 1
script.Parent.GunShot:Play()
if mouse.Target.Parent:FindFirstChild("Humanoid") or mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
if mouse.Target.Parent:IsA("Accessory") then
script.Parent.Damage:FireServer(mouse.Target.Parent.Parent, damage)
else
script.Parent.Damage:FireServer(mouse.Target.Parent, damage)
end
end
end
wait(shoottime)
until script.Parent.Deactivated
else -- Non Automatic
if shootdb == true then
shootdb = false
if ammo > 0 and not reloading then
script.Parent.GunShot:Stop()
ammo = ammo - 1
script.Parent.GunShot:Play()
if mouse.Target.Parent:FindFirstChild("Humanoid") or mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
if mouse.Target.Parent:IsA("Accessory") then
script.Parent.Damage:FireServer(mouse.Target.Parent.Parent, damage)
else
script.Parent.Damage:FireServer(mouse.Target.Parent, damage)
end
end
wait(shoottime)
shootdb = true
elseif reloading == false then
if canreload == true then
reload()
script.Parent.GunShot:Stop()
end
end
while wait(0.1) do
if canreload == true then
textlabel.Text = (ammo).." / "..maxammo
else
textlabel.Text = ammo
end
end
end
end
end)