Shotgun not working as wanted

Hi! I’ve made a shotgun, and when I shoot a zombie with my gun, the zombie freezes mid-air, then floats and falls apart, all while the zombie is still alive. The HumanoidRootPart of the torso becomes invisible but still follows the player and attacks me. However, I want the zombie to keep walking and only have a bit of damage when I shoot it.

Additionally, I tried to create an ammo GUI above the gun to display the ammo count, but the GUI doesn’t appear. Does anyone know how to fix this issue? By the way, here is the script:
local tool = script.Parent
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local bulletPrefab = replicatedStorage:WaitForChild(“BulletPrefab”)

local bulletsFolder = game.Workspace:WaitForChild(“Bullets”)
local zombieFolder = game.Workspace:WaitForChild(“Zombies”) – Assuming zombies are in a folder named “Zombies”

local MAX_BULLETS = 3 – Maximum bullets in the gun
local RELOAD_TIME = 3 – Time in seconds to reload
local SHOOT_COOLDOWN = 0.5 – Cooldown between shots in seconds

local bulletCount = MAX_BULLETS
local isReloading = false
local canShoot = true

– Create and update the bullet counter UI
local bulletCounter =“TextLabel”)
bulletCounter.Parent = tool
bulletCounter.Text = bulletCount … “/” … MAX_BULLETS
bulletCounter.Size =, 100, 0, 30)
bulletCounter.Position =, 0, 1, 10)
bulletCounter.BackgroundTransparency = 1
bulletCounter.TextColor3 =, 1, 1)
bulletCounter.TextStrokeColor3 =, 0, 0)
bulletCounter.TextStrokeTransparency = 0.5
bulletCounter.Font = Enum.Font.SourceSansBold
bulletCounter.TextSize = 20

local function updateBulletCounter()
bulletCounter.Text = bulletCount … “/” … MAX_BULLETS

local function onBulletHit(hit, bullet)
local character = game.Players:GetPlayerFromCharacter(hit.Parent)
local targetHumanoid = hit.Parent:FindFirstChild(“Humanoid”)

if character and targetHumanoid then
    targetHumanoid:TakeDamage(10)  -- Damage the humanoid
elseif hit.Parent:IsDescendantOf(zombieFolder) then
    -- Assuming zombies are in a folder named "Zombies"
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:TakeDamage(10)  -- Damage the humanoid if it exists
    -- Anchoring the zombie to prevent it from floating
    local zombieModel = hit.Parent
    for _, part in pairs(zombieModel:GetChildren()) do
        if part:IsA("BasePart") then
            part.Anchored = true

-- Create an explosion effect when the bullet hits something
local explosion ="Explosion")
explosion.BlastRadius = 5
explosion.BlastPressure = 1000
explosion.Position = bullet.Position
explosion.Parent = game.Workspace



local function createBullet(character)
if bulletCount <= 0 or isReloading or not canShoot then
return – No bullets, reloading, or on cooldown

bulletCount = bulletCount - 1
canShoot = false

local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local head = character:WaitForChild("Head")

local bulletSpeed = 100

-- Calculate the initial position of the bullet
local bulletPosition = humanoidRootPart.Position + humanoidRootPart.CFrame.lookVector * 2  -- Offset bullet position forward

-- Calculate the right vector based on the head's look vector
local headLookVector = (head.CFrame *, 0, -1)).lookVector
local bulletRightVector = headLookVector:Cross(, 1, 0)).unit

-- Adjust the bullet position with offsets
local bulletPositionOffset = headLookVector * 3 + bulletRightVector * 1 +, -0.1, 0)  -- Adjusted down and right offset
local bulletPositionAdjusted = bulletPosition + bulletPositionOffset

local bullet = bulletPrefab:Clone()
bullet.Position = bulletPositionAdjusted

-- Create BodyVelocity to move the bullet when unanchored
local bodyVelocity ="BodyVelocity")
bodyVelocity.Velocity = humanoidRootPart.CFrame.lookVector * bulletSpeed
bodyVelocity.MaxForce =, math.huge, math.huge)
bodyVelocity.Parent = bullet

bullet.Parent = bulletsFolder

    onBulletHit(hit, bullet)

canShoot = true


local function reloadGun()
isReloading = true
bulletCount = MAX_BULLETS
isReloading = false

if bulletCount <= 0 then
elseif not isReloading then
local character = game.Players.LocalPlayer.Character
if character then

– Ensure the tool variable is properly defined
if not tool or not tool:IsA(“Tool”) then
print(“Tool not found or incorrect type:”, tool)
– Parent the tool to the character’s backpack
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
tool.Parent = player.Backpack

– Initialize the bullet counter


is anyone gonna help because i don’t know how to figure this out

1 Like

You can try adding a boolean to the zombie where it tracks whether it should continue tracking players or not. For the ammo, did you make sure all enabled/visible properties are set to true? Try using print statements to see if certain events/functions are firing.


i did that yeah but it doesn’t have anything to do with the zombie but with the gun script itself

1 Like

What do you mean? The GUI? You mentioned the zombie kept tracking which I suggest adding a boolean. Also assuming by you saying “I did,” which I think you’re referring to the print statement, I noticed there aren’t any enabled or visible switching to true in your code.


ok that’s true idk what this bug is tho it is supposed to damage the zombie instead of tearing it apart

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