Gun doesn't shoot after reload

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix the reloading system, Gui does work but the shooting system doesnt work
  2. What is the issue? Include screenshots / videos if possible!

    The video that gun doesnt shoot
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried to make different ways to add ammo after reload but none of the ways didnt work

Local script of the gun, this script contains reload system, firing and others

tool = script.Parent
fireRemote = tool:WaitForChild("fireRemote")
reloadRemote = tool:WaitForChild("reloadRemote")
local settings = require(script.Parent.Settings)

playerService = game:GetService("Players")
client = playerService.LocalPlayer
cursor = client:GetMouse() 
user_inputService = game:GetService("UserInputService")
runService = game:GetService("RunService")

Mouse_Icon = "rbxasset://textures/GunCursor.png"
Mouse = nil

equipped = false
reloading = false

db = false

enabled = true
local ammo = settings["ammo"]
local mag = settings["mag"]
function fire()
	if enabled == false then return end
	if ammo > -0 and tool.Parent:FindFirstChild("Humanoid").Health > 0 then
		ammo = ammo - 1
		if client.PlayerGui:FindFirstChild("AmmoGUI") then
			client.PlayerGui.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
		end
		fireRemote:FireServer(cursor.Hit.Position)
	end
	if ammo == 0 then
		enabled = false
		tool.Handle.NoAmmo:Play()
	end
end
tool.Equipped:Connect(function()
	equipped = true
	if script.Parent:FindFirstChild("AmmoGUI") then
		script.Parent.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
		script.Parent.AmmoGUI.ToolName.Text = script.Parent.Name
		script.Parent.AmmoGUI.Parent = client.PlayerGui
	end
end)

tool.Unequipped:Connect(function()
	equipped = false
	if client.PlayerGui:FindFirstChild("AmmoGUI") then
		client.PlayerGui.AmmoGUI.Parent = script.Parent
	end
end)

if settings["autofire"] == true then
	runService.Stepped:Connect(function()
		if user_inputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
			if db == false then
			db = true
			fire()
			wait(settings["firerate"])
			db = false
			end
		end
	end)
end

user_inputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R and not reloading then reloading = true
		if tool.Handle:FindFirstChild("rldsound")then tool.Handle.rldsound:Play() end
		if client.PlayerGui:FindFirstChild("AmmoGUI") then	
			client.PlayerGui.AmmoGUI.Frame.Ammo.Text = "Reloading"		
		end
		tool.Handle.reloadSound:Play()
		wait(settings["reloadtime"])
		ammo = settings["ammo"]
		reloadRemote:FireServer()
		if client.PlayerGui:FindFirstChild("AmmoGUI") then	
			client.PlayerGui.AmmoGUI.Frame.Ammo.Text = "Reloading"		
		end	
		mag -= 1
		client.PlayerGui.AmmoGUI.Frame.Ammo.Text = ammo.."/"..mag
		reloading = false
	end
end)
tool.Activated:Connect(fire)

The firing script

tool = script.Parent
firePart = tool:WaitForChild("Hole")
fireRemote = tool:WaitForChild("fireRemote")
reloadRemote = tool:WaitForChild("reloadRemote")
userHumanoid = tool.Parent:FindFirstChild("Humanoid")
local settings = require(tool.Settings)

ammo = settings["ammo"]
mag = settings["mag"]

range = settings["range"]

enabled = true

Debris = game:GetService("Debris")

debrisService = game:GetService("Debris")

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
end

function UntagHumanoid(humanoid)
	for i, v in pairs(humanoid:GetChildren()) do
		if v:IsA("ObjectValue") and v.Name == "creator" then
			v:Destroy()
		end
	end
end

fireRemote.OnServerEvent:Connect(function(player, position)
		local origin = firePart.Position
		local direction = (position - origin).Unit*range
		local filter = RaycastParams.new()
		filter.FilterType = Enum.RaycastFilterType.Exclude
		filter.FilterDescendantsInstances = {tool.Parent}
		local result = workspace:Raycast(origin, direction, filter)
		local intersection = result and result.Position or origin + direction
		local distance = (origin - intersection).Magnitude
		local bullet = Instance.new("Part")
		bullet.BrickColor = BrickColor.new("New Yeller")
		bullet.Anchored = true
		bullet.CanCollide = false
		bullet.Material = Enum.Material.Neon
		bullet.Size = Vector3.new(.2,.2,distance)
		bullet.CFrame = CFrame.new(origin, intersection)*CFrame.new(0, 0, -distance/2)
		bullet.Parent = workspace
		
		local fireSoundClone = tool.Shot:Clone()
		fireSoundClone.Parent = tool.Handle
		fireSoundClone:Play()
		if result then
			local part = result.Instance
			local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")

			if humanoid then
				UntagHumanoid(humanoid)
				TagHumanoid(humanoid,player)
				humanoid:TakeDamage(settings["damage"])
			end
		end
		debrisService:AddItem(bullet, 0.05)
		debrisService:AddItem(fireSoundClone, fireSoundClone.TimeLength)
end)
reloadRemote.OnServerEvent:Connect(function()
	ammo = settings["ammo"]
end)

Any of your help i will appreciate it

1 Like

Why did you make it so it sets ammo to its self? That makes no sense. Make a value in the settings that is called “max ammo” (maximal ammo) and set the ammo to that when reloading. Or is that the problem? I dont know man, your code is a big mess. And the Gui says there is full ammo in the mag.

1 Like

So you want me to use value settings instead of module settings?
EDIT: + why are you saying that my code is a mess, if you want ,rescript the whole code

1 Like

He’s saying your code is a mess because you’re asking for help, and your code is a mess. That makes it a lot more time-consuming to help you.

1 Like

In the fire function you’re setting enabled to false and not setting it back to true again

1 Like

do you mean about

enabled == false

?

1 Like

ahh man you need to set enabled to true when you reload.

1 Like

Yes, currently when your ammo reaches 0 you’re setting enabled to false which is activating your debounce and preventing the gun from firing, and you don’t seem to be setting enabled back to true when the gun has finished reloading the ammo so your debounce is stuck

2 Likes

Thank you! I fixed the gun and it is now works

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.