Gun framework not working as expected

So I was working on some gun framework and I came across the fact that it doesn’t work.

Here’s my code:

Server Script

game.ReplicatedStorage.Damage.OnServerEvent:Connect(function(player, damage)
     local hum = player.Character.Humanoid
     hum:TakeDamage(damage)
end)

Gun Server Client:

local gun = script.Parent
local max = 25
local ammo = max
local reloading = false
local player = game.Players.LocalPlayer
local damage = game.ReplicatedStorage.Damage
local mouse = player:GetMouse()
local muzzle = script.Parent.Muzzle
local UIS = game:GetService("UserInputService")

gun.Equipped:Connect(function()
     local function reload()
         if not reloading then
             reloading = true
             task.wait(3)
             ammo = max
             reloading = false
         end
     end

    mouse.Button1Down:Connect(function()
          repeat wait(0.3)
               ammo = ammo - 1
               local bullet = Instance.new("Part")
               bullet.Size = (0.4,0.1,0.1)
               bullet.Position = muzzle.Position
               bullet.Velocity = mouse.Hit.LookVector * 450
               bullet.Touched:Connect(function(hit)
                   if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:IsA("Model") then
                       damage:FireServer(hit.Parent, 8.5)
                   end
               end) 
               
          until mouse.Button1Up or ammo == 0

           UIS.InputBegan:Connect(function(input)
                if input.KeyCode == Enum.KeyCode.R and not reloading and ammo < max then
                     reload()
                end
           end)
     end)  
end)
1 Like

Can you specify, what doesn’t work in the Gun Framework?

the bullets aren’t shooting and the enemy isn’t taking any damage.

You will have to debug your code.
Put many print statements around your code, see which ones print and which ones not.
For each one that doesn’t print, find the root cause, and fix it.