Gun still shooting when reloading

So I’m making a shotgun and the problem with it is that you can still shoot while the gun is reloading and I can’t see the issue. I’ve searched for other articles indicating the same problem I have but none of them helped. Here’s the code:

local player = game.Players.LocalPlayer

repeat wait() until player.Character
--repeat wait() until player.Character.Humanoid

local char = player.Character or player.CharacterAdded:Wait()

local userinputservice = game:GetService("UserInputService")
local hum = char:WaitForChild("Humanoid")
local ammo = script.Parent:WaitForChild("Ammo")
local maxammo = script.Parent:WaitForChild("MaxAmmo")
local weapongui = script.Parent:WaitForChild("Weapon")
local equipanim = hum:LoadAnimation(script.Parent:WaitForChild("EquipAnim"))
local shootanim = hum:LoadAnimation(script.Parent:WaitForChild("ShootAnim"))
local aimanim = hum:LoadAnimation(script.Parent:WaitForChild("AimAnim"))
local reloadanim = hum:LoadAnimation(script.Parent:WaitForChild("ReloadAnim"))
local crawlanim = hum:LoadAnimation(player.Character:WaitForChild("CrawlAnim"))
local crawlidleanim = hum:LoadAnimation(player.Character:WaitForChild("CrawlIdleAnim"))
local equipped = false
local shooting = false
local reloading = false
local crawling = false

script.Parent.Equipped:Connect(function(mouse)
	equipped = true
	mouse.Icon = "rbxassetid://1588092778"
	weapongui:Clone().Parent = player.PlayerGui
	equipanim:Play()
	
	local function Reload()
		reloadanim:Play()
		script.Parent.Handle.Reload:Play()
		wait(3)
		ammo.Value = maxammo.Value
	end
	
	local function Shoot()
		script.Parent.Shoot:FireServer(script.Parent.Hole.Position, mouse.Hit.Position)
		shootanim:Play()

		if ammo.Value <= 0 and reloading == false then
			shooting = false
			reloading = true
			Reload()
			wait(3)
			reloading = false
			shooting = true

		else
			ammo.Value -= 1
		end
	end
	
	userinputservice.InputBegan:Connect(function(input, gameproccessed)
		if equipped == true and input.KeyCode == Enum.KeyCode.R and reloading == false then
			shooting = false
			reloading = true
			Reload()
			reloading = false
			shooting = true
		end

		if gameproccessed then
			return
		end
	end)
	
	mouse.Button1Down:Connect(function()
		shooting = true
		--script.Parent.Shoot:FireServer(script.Parent.Hole.Position, mouse.Hit.Position)
		--shootanim:Play()

		if ammo.Value <= 0 and reloading == false then
			shooting = false
			reloading = true
			Reload()
			wait(3)
			reloading = false
			shooting = true

		else
			ammo.Value -= 1
			Shoot()
		end
	end)
	
	mouse.Button1Up:Connect(function()
		shooting = false
	end)
	
	script.Parent.Unequipped:Connect(function()
		equipped = false
		reloading = false
		shooting = false
		mouse.Icon = ""
		reloadanim:Stop()
		equipanim:Stop()
		aimanim:Stop()

		if crawlanim.IsPlaying == true or crawlidleanim.IsPlaying == true then
			player.Character.Humanoid.WalkSpeed = 8

		else
			player.Character.Humanoid.WalkSpeed = 25
		end

		if player.PlayerGui:FindFirstChild("Weapon") then
			player.PlayerGui["Weapon"]:Destroy()
		end
	end)
end)

I think it has to be something here, maybe try

if ammo.Value <= 0 and reloading == false then
			shooting = false
			reloading = true
			Reload()
			wait(3)
			reloading = false
			shooting = true

		elseif ammo.Value > 0 and reloading == false then
			ammo.Value -= 1
			Shoot()
		end

Edit: This is the one in mouse.Button1Down. Also, why do you hae that exact same code i nthe Shoot function? It’s going to make it take 2 ammo instead

Thanks, it works now. And yea I did remove that same exact if statement.

Glad to be help to you! If you any more issues don’t be afraid to make another post on the DevForums!

1 Like