local players = game:GetService("Players")
local player = players.LocalPlayer
local playergui = player:FindFirstChild("PlayerGui")
local mouse = player:GetMouse()
local char = nil
local hum = nil
local ReloadAnim
local ReloadTrack = nil
local shotanim
local shotanimtrack = nil
local tool = script.Parent
local handle = tool:FindFirstChild("Handle")
local larrel = handle and handle:FindFirstChild("larrel")
local debounce = false
local userinput = game:GetService("UserInputService")
local ammo = 8
local maxAmmo = 8
local reloading = false
local jammed = false
local STOP = false
local function reload ()
if reloading == false then
reloading = true
ReloadAnim = tool:WaitForChild("Reload")
ReloadTrack = hum:LoadAnimation(ReloadAnim)
ReloadTrack:Play()
local part = Instance.new("Part")
part.Position = tool.Handle.Position
part.Size = Vector3.new(0.201, 0.776, 0.32)
part.CFrame = tool.Handle.CFrame * CFrame.Angles(0, math.rad(90), 0)
part.Parent = workspace
part.CanCollide = true
part.BrickColor = BrickColor.new("Black")
part.Material = Enum.Material.Metal
script.Parent.Handle["Gun Reload"]:Play()
tool.Parent:WaitForChild("run?").Value = false
tool.Parent:WaitForChild("Humanoid").WalkSpeed = 8
task.wait(2.1)
local random = math.random(1,2)
if random == 1 then
print("gunnotjammed")
else
jammed = true
script.Parent.Handle.JAMMED:Play()
print("gungotjammed")
end
tool.Parent:WaitForChild("run?").Value = true
tool.Parent:WaitForChild("Humanoid").WalkSpeed = 17
ammo = maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Text = ""..ammo.."/"..maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 0
script.Parent.Handle.theslidle.Transparency = 1
script.Parent.Handle.theslidle2.Transparency = 0
script.Parent.Handle["Tactical Pistol Slide Release"]:Play()
task.wait(.5)
script.Parent.Handle.theslidle.Transparency = 0
script.Parent.Handle.theslidle2.Transparency = 1
if ReloadTrack then
ReloadTrack:Stop()
end
reloading = false
part:Destroy()
end
end
-- Shooting
tool.Activated:Connect(function()
if debounce == false and ammo > 0 and reloading == false and jammed == false and STOP == false then
debounce = true
ammo -= 1
local direction = (mouse.Hit.Position - tool.Handle.Barrel.Position).Unit
tool.Shoot:FireServer(direction)
if shotanimtrack then
shotanimtrack:Play()
end
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(2.5),0,0)
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Text = ""..ammo.."/"..maxAmmo
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 0
task.wait(0.1)
debounce = false
elseif ammo <= 0 and reloading == false then
reload()
end
end)
tool.Equipped:Connect(function()
player.PlayerGui.jammedgui.Frame.Visible = true
mouse.Icon = "rbxasset://textures/GunCursor.png"
player.PlayerGui.AmmoGui3.Enabled = true
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 0
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Text = ""..ammo.."/"..maxAmmo
shotanim = tool:WaitForChild("Animation")
shotanimtrack = player.Character.Humanoid:LoadAnimation(shotanim)
char = tool.Parent
hum = char:WaitForChild("Humanoid")
STOP= true
task.wait(0.5)
STOP = false
end)
tool.Unequipped:Connect(function()
player.PlayerGui.jammedgui.Frame.Visible = false
player.Character:WaitForChild("run?").Value = true
player.Character:WaitForChild("Humanoid").WalkSpeed = 17
reloading = false ----this isnt working some how
script.Parent.Handle["Gun Reload"]:Stop()
mouse.Icon = ""
player.PlayerGui.AmmoGui3.Enabled = false
player.PlayerGui.AmmoGui3.Frame3.TextLabelg.Transparency = 1
script.Parent.Handle["Gun Reload"]:Stop()
hum = nil
char = nil
shotanim = nil
shotanimtrack = nil
if shotanim then
shotanimtrack:Stop()
end
if ReloadTrack then
ReloadTrack:Stop() ---animantions dont stop for some reason
end
if ReloadAnim then
ReloadAnim = nil
end
end)
ive tried making the reloading boolean to false but it didnt work


