CasingMesh.Parent=CasingBase function OnFire()if IsShooting then return end if MyHumanoid and MyHumanoid.Health>0 then if RecoilTrack and AmmoInClip>0 then end IsShooting=true if AmmoInClip>0 and not Reloading then if Handle:FindFirstChild("\070\105\114\101\083\111\117\110\100")then Handle.FireSound:Play()end CreateFlash()Tool.SetIcon:FireClient(game.Players:GetPlayerFromCharacter(Tool.Parent),"\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\087\097\105\116\067\117\114\115\111\114\046\112\110\103")local h=MOUSE_TARGET for b=1,BulletCount,1 do local I=(h-Handle.Position).unit I=((CFrame.new(Vector3.new(0,0,0),I)*CFrame.Angles(0,0,(math.random()*2)*math.pi))*CFrame.Angles(math.random()*Spread,0,0)).lookVector local r,Q=RayCast(Handle.Position,I,Range)local l if r then l=CreateBullet(Q,r)end if r and r.Parent then local h=r.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")or r.Parent.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if h then local b=game.Players:GetPlayerFromCharacter(h.Parent)if not GLib.IsTeammate(MyPlayer,b)then GLib.TagHumanoid(MyPlayer,h,1)h:TakeDamage(Damage)if l then l:Destroy()l=nil end end end end end local b=CasingBase:Clone()b.Position=Tool.Handle.Position+Vector3.new(0,1,0)b.Velocity=(Vector3.new(math.random()-.5,.5+math.random(),math.random()-.5)-1.5*(Tool.Handle.CFrame*CFrame.Angles(0,math.pi/4,0)).lookVector)*20 DebrisService:AddItem(b,2.5)b.Parent=game.Workspace AmmoInClip=AmmoInClip-1 UpdateAmmo(AmmoInClip)wait(FireRate-.2)if AmmoInClip>0 then if PumpTrack then PumpTrack:Play()end if Handle:FindFirstChild("\080\117\109\112\083\111\117\110\100")then Handle.PumpSound:Play()end wait(.2)end Tool.SetIcon:FireClient(game.Players:GetPlayerFromCharacter(Tool.Parent),"\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103")end IsShooting=false if AmmoInClip==0 then Reload()end if RecoilTrack then RecoilTrack:Stop()end end end function UpdateAmmo(h)if WeaponGui and(WeaponGui:FindFirstChild("\065\109\109\111\072\117\100")and WeaponGui.AmmoHud:FindFirstChild("\067\108\105\112\065\109\109\111"))then WeaponGui.AmmoHud.ClipAmmo.Text=AmmoInClip end end function OnMouseDown()LeftButtonDown=true OnFire()end function OnMouseUp()LeftButtonDown=false end function OnKeyDown(h)if string.lower(h)=="\114"then Reload()end end Tool.Input.OnServerEvent:connect(function(h,b,...)if h.Character==Tool.Parent then if b=="\077\111\117\115\101\049"then local h,b=...if h then OnMouseDown()else OnMouseUp()end elseif b=="\075\101\121"then local h,b=...if h then OnKeyDown(b)end elseif b=="\077\111\117\115\101\077\111\118\101"then local h=...MOUSE_TARGET=h end end end)function OnEquipped()EquipAnim=WaitForChild(Tool,"\069\113\117\105\112")PumpAnim=WaitForChild(Tool,"\082\101\108\111\097\100")FireSound=WaitForChild(Handle,"\070\105\114\101\083\111\117\110\100")MyCharacter=Tool.Parent MyPlayer=(game:GetService("\080\108\097\121\101\114\115")):GetPlayerFromCharacter(MyCharacter)MyHumanoid=MyCharacter:FindFirstChild("\072\117\109\097\110\111\105\100")MyTorso=MyCharacter:FindFirstChild("\084\111\114\115\111")WeaponGui=(WaitForChild(Tool,"\087\101\097\112\111\110\072\117\100")):Clone()if WeaponGui and MyPlayer then WeaponGui.Parent=MyPlayer.PlayerGui UpdateAmmo(AmmoInClip)end if EquipAnim then Tool.Grip=CFrame.new(.132808685,.00749024749,.526850462,.925221086,.000443253666,.379427731,.00859767944,.999718785,-0.0221330915,-0.379331142,.0237402022,.924956799)EquipTrack=MyHumanoid:LoadAnimation(EquipAnim)EquipTrack:Play()end if PumpAnim then PumpTrack=MyHumanoid:LoadAnimation(PumpAnim)end Tool.SetIcon:FireClient(game.Players:GetPlayerFromCharacter(Tool.Parent),"\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\092\071\117\110\067\117\114\115\111\114\046\112\110\103")end
--CasingMesh.Scale = Vector3.new(.75,.75,.75)
CasingMesh.Parent = CasingBase

function OnFire()
	if IsShooting then
		return
	end
	if MyHumanoid and MyHumanoid.Health > 0 then
		if RecoilTrack and AmmoInClip > 0 then
		end
		IsShooting = true
		if AmmoInClip > 0 and not Reloading then
			--if RecoilTrack then RecoilTrack:Play() end
			if Handle:FindFirstChild("FireSound") then
				Handle.FireSound:Play()
			end
			CreateFlash()
			Tool.SetIcon:FireClient(
				game.Players:GetPlayerFromCharacter(Tool.Parent),
				"rbxasset://textures\\GunWaitCursor.png"
			)
			local targetPoint = MOUSE_TARGET
			for i = 1, BulletCount do
				local shootDirection = (targetPoint - Handle.Position).unit
				-- Adjust the shoot direction randomly off by a little bit to account for recoil
				-- moves random*spread in a random angle from center shot point (center bias)
				shootDirection = ((CFrame.new(Vector3.new(0, 0, 0), shootDirection) * CFrame.Angles(
					0,
					0,
					math.random() * 2 * math.pi
				)) * CFrame.Angles(math.random() * Spread, 0, 0)).lookVector
				local hitObject, bulletPos = RayCast(Handle.Position, shootDirection, Range)
				local bullet
				-- Create a bullet here
				if hitObject then
					bullet = CreateBullet(bulletPos, hitObject)
				end
				if hitObject and hitObject.Parent then
					local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
						or hitObject.Parent.Parent:FindFirstChild("Humanoid")
					if hitHumanoid then
						local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
						if not GLib.IsTeammate(MyPlayer, hitPlayer) then
							GLib.TagHumanoid(MyPlayer, hitHumanoid, 1)
							hitHumanoid:TakeDamage(Damage)
							if bullet then
								bullet:Destroy()
								bullet = nil
								--bullet.Transparency = 1
							end
						end
					end
				end
			end

			local casing = CasingBase:Clone()
			casing.Position = Tool.Handle.Position + Vector3.new(0, 1, 0)
			casing.Velocity = (
				Vector3.new((math.random() - 0.5), (0.5 + math.random()), (math.random() - 0.5))
				- 1.5 * (Tool.Handle.CFrame * CFrame.Angles(0, math.pi / 4, 0)).lookVector
			) * 20
			DebrisService:AddItem(casing, 2.5)
			casing.Parent = game.Workspace

			AmmoInClip = AmmoInClip - 1
			UpdateAmmo(AmmoInClip)
			wait(FireRate - 0.2)

			if AmmoInClip > 0 then
				if PumpTrack then
					PumpTrack:Play()
				end
				if Handle:FindFirstChild("PumpSound") then
					Handle.PumpSound:Play()
				end
				wait(0.2)
			end
			Tool.SetIcon:FireClient(
				game.Players:GetPlayerFromCharacter(Tool.Parent),
				"rbxasset://textures\\GunCursor.png"
			)
		end
		IsShooting = false
		if AmmoInClip == 0 then
			Reload()
		end
		if RecoilTrack then
			RecoilTrack:Stop()
		end
	end
end

function UpdateAmmo(value)
	if WeaponGui and WeaponGui:FindFirstChild("AmmoHud") and WeaponGui.AmmoHud:FindFirstChild("ClipAmmo") then
		WeaponGui.AmmoHud.ClipAmmo.Text = AmmoInClip
	end
	--if WeaponGui and WeaponGui:FindFirstChild('AmmoHud') and WeaponGui.AmmoHud:FindFirstChild('TotalAmmo') then
	--	WeaponGui.AmmoHud.TotalAmmo.Text = SpareAmmo
	--end
end

function OnMouseDown()
	LeftButtonDown = true
	OnFire()
end

function OnMouseUp()
	LeftButtonDown = false
end

function OnKeyDown(key)
	if string.lower(key) == "r" then
		Reload()
	end
end

Tool.Input.OnServerEvent:connect(function(client, action, ...)
	if client.Character == Tool.Parent then
		if action == "Mouse1" then
			local down, pos = ...

			if down then
				OnMouseDown()
			else
				OnMouseUp()
			end
		elseif action == "Key" then
			local down, key = ...

			if down then
				OnKeyDown(key)
			end
		elseif action == "MouseMove" then
			local pos = ...

			MOUSE_TARGET = pos
		end
	end
end)

function OnEquipped()
	EquipAnim = WaitForChild(Tool, "Equip")
	PumpAnim = WaitForChild(Tool, "Reload")
	FireSound = WaitForChild(Handle, "FireSound")

	MyCharacter = Tool.Parent
	MyPlayer = game:GetService("Players"):GetPlayerFromCharacter(MyCharacter)
	MyHumanoid = MyCharacter:FindFirstChild("Humanoid")
	MyTorso = MyCharacter:FindFirstChild("Torso")
	WeaponGui = WaitForChild(Tool, "WeaponHud"):Clone()
	if WeaponGui and MyPlayer then
		WeaponGui.Parent = MyPlayer.PlayerGui
		UpdateAmmo(AmmoInClip)
	end
	if EquipAnim then
		Tool.Grip = CFrame.new(
			0.132808685,
			0.00749024749,
			0.526850462,
			0.925221086,
			0.000443253666,
			0.379427731,
			0.00859767944,
			0.999718785,
			-0.0221330915,
			-0.379331142,
			0.0237402022,
			0.924956799
		)
		EquipTrack = MyHumanoid:LoadAnimation(EquipAnim)
		EquipTrack:Play()
	end
	if PumpAnim then
		PumpTrack = MyHumanoid:LoadAnimation(PumpAnim)
	end

	Tool.SetIcon:FireClient(game.Players:GetPlayerFromCharacter(Tool.Parent), "rbxasset://textures\\GunCursor.png")
end
