function RayCast(I,j,b)local o,u=game.Workspace:FindPartOnRay(Ray.new(I+j*.01,j*b),Handle)if o and u then local K=b-(u-I).magnitude if RayIgnoreCheck(o,u)and K>0 then return RayCast(u,j,K)end end return o,u end function TagHumanoid(I,j)while I:FindFirstChild("\099\114\101\097\116\111\114")do(I:FindFirstChild("\099\114\101\097\116\111\114")):Destroy()end local b=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")b.Value=j b.Name="\099\114\101\097\116\111\114"b.Parent=I DebrisService:AddItem(b,1)end local function I()if not FlashHolder then FlashHolder=Instance.new("\080\097\114\116",Tool)FlashHolder.Name="\070\108\097\115\104\072\111\108\100\101\114"FlashHolder.Transparency=1 FlashHolder.CanCollide=false FlashHolder.FormFactor="\067\117\115\116\111\109"FlashHolder.Size=Vector3.new(.4,.4,.4)FlashHolder.Position=Tool.Handle.Position local I=Instance.new("\077\097\110\117\097\108\087\101\108\100")I.C0=CFrame.new(0,0,0,1,0,0,0,1,0,0,0,1)I.C1=CFrame.new(0,.4,-2.4,0,0,1,1,0,0,0,1,0)I.Part0=FlashHolder I.Part1=Tool.Handle I.Parent=FlashHolder end local I=Instance.new("\070\105\114\101",FlashHolder)I.Color=Color3.new(1,.54901960784314,0)I.SecondaryColor=Color3.new(1,0,0)I.Size=.3 DebrisService:AddItem(I,FireRate/1.5)end local j=Instance.new("\080\097\114\116")j.FormFactor=Enum.FormFactor.Custom j.Size=Vector3.new(1,1,1)j.BrickColor=BrickColor.new("\066\108\097\099\107")j.CanCollide=false j.Anchored=true j.TopSurface=Enum.SurfaceType.Smooth j.BottomSurface=Enum.SurfaceType.Smooth j.Name="\066\117\108\108\101\116"local b=Instance.new("\083\112\101\099\105\097\108\077\101\115\104")b.MeshType="\083\112\104\101\114\101"b.Scale=Vector3.new(.2,.2,.2)b.Parent=j local function o(I)local b=j:Clone()b.CFrame=CFrame.new(I)b.Parent=game.Workspace DebrisService:AddItem(b,2.5)return b end local function u()if not Reloading then Reloading=true MyMouse.Icon="\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"if AmmoInClip~=ClipSize then if PumpTrack then PumpTrack:Stop()end for I=1,6,1 do if PumpTrack then PumpTrack:Play()end if Handle:FindFirstChild("\080\117\109\112\083\111\117\110\100")then Handle.PumpSound:Play()end wait(ReloadTime/6)end local I=ClipSize-AmmoInClip AmmoInClip=AmmoInClip+I UpdateAmmo(AmmoInClip)end MyMouse.Icon="\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"Reloading=false end end local K=Instance.new("\080\097\114\116")K.FormFactor=Enum.FormFactor.Custom K.Elasticity=0 K.Size=Vector3.new(.3,.3,.5)local t=Instance.new("\083\112\101\099\105\097\108\077\101\115\104")t.MeshId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\057\052\050\052\056\049\050\052"t.TextureId="\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\057\052\050\049\057\052\055\048"
-- @preconditions: vec should be a unit vector, and 0 < rayLength <= 1000
function RayCast(startPos, vec, rayLength)
	local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * 0.01), vec * rayLength), Handle)
	if hitObject and hitPos then
		local distance = rayLength - (hitPos - startPos).magnitude
		if RayIgnoreCheck(hitObject, hitPos) and distance > 0 then
			-- there is a chance here for potential infinite recursion
			return RayCast(hitPos, vec, distance)
		end
	end
	return hitObject, hitPos
end

function TagHumanoid(humanoid, player)
	-- Add more tags here to customize what tags are available.
	while humanoid:FindFirstChild("creator") do
		humanoid:FindFirstChild("creator"):Destroy()
	end
	local creatorTag = Instance.new("ObjectValue")
	creatorTag.Value = player
	creatorTag.Name = "creator"
	creatorTag.Parent = humanoid
	DebrisService:AddItem(creatorTag, 1)
end

local function CreateFlash()
	if not FlashHolder then
		FlashHolder = Instance.new("Part", Tool)
		FlashHolder.Name = "FlashHolder"
		FlashHolder.Transparency = 1
		FlashHolder.CanCollide = false
		FlashHolder.FormFactor = "Custom"
		FlashHolder.Size = Vector3.new(0.4, 0.4, 0.4)
		FlashHolder.Position = Tool.Handle.Position
		local Weld = Instance.new("ManualWeld")
		Weld.C0 = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)
		Weld.C1 = CFrame.new(0, 0.4, -2.4, 0, 0, 1, 1, 0, 0, 0, 1, 0)
		Weld.Part0 = FlashHolder
		Weld.Part1 = Tool.Handle
		Weld.Parent = FlashHolder
	end
	local flash = Instance.new("Fire", FlashHolder)
	flash.Color = Color3.new(1, 140 / 255, 0)
	flash.SecondaryColor = Color3.new(1, 0, 0)
	flash.Size = 0.3
	DebrisService:AddItem(flash, FireRate / 1.5)
end

local BulletBase = Instance.new("Part")
BulletBase.FormFactor = Enum.FormFactor.Custom
BulletBase.Size = Vector3.new(1, 1, 1)
BulletBase.BrickColor = BrickColor.new("Black")
BulletBase.CanCollide = false
BulletBase.Anchored = true
BulletBase.TopSurface = Enum.SurfaceType.Smooth
BulletBase.BottomSurface = Enum.SurfaceType.Smooth
BulletBase.Name = "Bullet"

local BulletMesh = Instance.new("SpecialMesh")
BulletMesh.MeshType = "Sphere"
BulletMesh.Scale = Vector3.new(0.2, 0.2, 0.2)
BulletMesh.Parent = BulletBase

local function CreateBullet(bulletPos)
	local bullet = BulletBase:Clone()

	bullet.CFrame = CFrame.new(bulletPos)
	bullet.Parent = game.Workspace
	DebrisService:AddItem(bullet, 2.5)

	return bullet
end

local function Reload()
	if not Reloading then
		Reloading = true
		MyMouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
		-- Don't reload if you are already full or have no extra ammo
		if AmmoInClip ~= ClipSize then
			if PumpTrack then
				PumpTrack:Stop()
			end
			for i = 1, 6 do
				if PumpTrack then
					PumpTrack:Play()
				end
				if Handle:FindFirstChild("PumpSound") then
					Handle.PumpSound:Play()
				end
				wait(ReloadTime / 6)
			end
			-- Only use as much ammo as you have
			local ammoToUse = ClipSize - AmmoInClip
			AmmoInClip = AmmoInClip + ammoToUse
			UpdateAmmo(AmmoInClip)
		end
		MyMouse.Icon = "rbxasset://textures\\GunCursor.png"
		Reloading = false
	end
end

local CasingBase = Instance.new("Part")
CasingBase.FormFactor = Enum.FormFactor.Custom
CasingBase.Elasticity = 0
CasingBase.Size = Vector3.new(0.3, 0.3, 0.5)
local CasingMesh = Instance.new("SpecialMesh")
CasingMesh.MeshId = "http://www.roblox.com/asset/?id=94248124"
CasingMesh.TextureId = "http://www.roblox.com/asset/?id=94219470"
