function tagHumanoid(f)local K=game.Players:playerFromCharacter(sp.Parent)if K~=nil then local k=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")k.Value=K k.Name="\099\114\101\097\116\111\114"k.Parent=f delay(2,function()if k~=nil then k.Parent=nil end end)end end function reload(f)reloading=true f.Icon=ReloadCursor while sp.Ammo.Value<ClipSize and(reloading and enabled)do wait(ReloadTime/ClipSize)if reloading then sp.Ammo.Value=sp.Ammo.Value+1 check()else break end end check()f.Icon=Cursors[1]reloading=false end function onKeyDown(f,K)f=f:lower()if f=="\114"and not reloading then reload(K)end end function movecframe(f,K)f.Parent=game.Lighting f.Position=K f.Parent=game.Workspace end function fire(f)sp.Handle.Fire:Play()t=r.Stepped:wait()last6=last5 last5=last4 last4=last3 last3=last2 last2=last last=t local K=Bullet:clone()local k=game.Lighting.BulletTexture:clone()k.BrickColor=BrickColor.new("\066\114\105\103\104\116 \114\101\100")k.Mesh.Scale=Vector3.new(.5,.5,2)local Z=0 Lengthdist=-RayLength/.5 local n=sp.Handle.CFrame*BarrlePos local x=f-n x=computeDirection(x)local V=CFrame.new(n,x+n)local b,w,o,d=raycast(game.Workspace,n,V*Vector3.new(0,0,Lengthdist)-n,function(f)if f.Name=="\071\108\097\115\115"then return true elseif f.Name=="\066\117\108\108\101\116"or f.Name=="\066\117\108\108\101\116\084\101\120\116\117\114\101"then return false elseif f:IsDescendantOf(sp.Parent)then return false elseif f.Name=="\072\097\110\100\108\101"then if f.Parent:IsDescendantOf(sp.Parent)then return false else return true end end return true end)K.Parent=game.Workspace k.Parent=game.Workspace if b~=nil then local f=b.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if f~=nil then local K=math.random(BaseDamage-BaseDamage*.25,BaseDamage+BaseDamage*.25)if b.Name=="\072\101\097\100"then K=K*1.25 elseif b.Name=="\084\111\114\115\111"then else K=K*.75 end if f.Health>0 then local k=game.Players:playerFromCharacter(f.Parent)local Z=game.Players:playerFromCharacter(sp.Parent)if k~=nil and Z~=nil then tagHumanoid(f)f:TakeDamage(K)else tagHumanoid(f)f:TakeDamage(K)end end end if b.Name=="\080\097\114\116\049\048"or b.Name=="\080\097\114\116\049\049"or b.Name=="\080\097\114\116\050\049"or b.Name=="\080\097\114\116\050\051"or b.Name=="\080\097\114\116\050\052"or b.Name=="\080\097\114\116\056"then rand=math.random(1,5)if rand==1 then workspace.GlassSound:play()b:breakJoints()end end if b.Parent:findFirstChild("\072\105\116")then b.Parent.Health.Value=b.Parent.Health.Value-BaseDamage/3 end distance=(n-w).magnitude K.CFrame=V*CFrame.new(0,0,-distance/2)K.Mesh.Scale=Vector3.new(.15,.15,distance)else K.CFrame=V*CFrame.new(0,0,-RayLength/2)K.Mesh.Scale=Vector3.new(.15,.15,RayLength)end if w~=nil then k.CFrame=K.CFrame movecframe(k,w)end local j=game:FindFirstChild("\068\101\098\114\105\115")if j==nil then local f=Instance.new("\068\101\098\114\105\115")f.Parent=game end check()game.Debris:AddItem(K,.05)game.Debris:AddItem(k,.5)end function onButton1Up(f)down=false end function onButton1Down(f)h=sp.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if not enabled or reloading or down or h==nil then return end if sp.Ammo.Value>0 and h.Health>0 then down=true enabled=false while down do if sp.Ammo.Value<=0 then break end if burst then local K=sp.Handle.CFrame*BarrlePos local k=(f.Hit.p-K).magnitude local Z=Vector3.new(math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k))fire(f.Hit.p+Z)sp.Ammo.Value=sp.Ammo.Value-1 if sp.Ammo.Value<=0 then break end wait(.05)local n=sp.Handle.CFrame*BarrlePos local x=((f.Hit.p+Z)-n).magnitude local V=Vector3.new(math.random(-0.01*x,.01*x),math.random(-0.01*x,.01*x),math.random(-0.01*x,.01*x))fire((f.Hit.p+Z)+V)sp.Ammo.Value=sp.Ammo.Value-1 if sp.Ammo.Value<=0 then break end wait(.05)fire(((f.Hit.p+Z)+V)+V)sp.Ammo.Value=sp.Ammo.Value-1 elseif shot then sp.Ammo.Value=sp.Ammo.Value-1 local K=sp.Handle.CFrame*BarrlePos local k=(f.Hit.p-K).magnitude local Z=Vector3.new(math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k))fire(f.Hit.p+Z)local n=((f.Hit.p+Z)-K).magnitude local x=Vector3.new(math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n))fire((f.Hit.p+Z)+x)local V=Vector3.new(math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n))fire((f.Hit.p+Z)+V)local b=Vector3.new(math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n),math.random(-0.02*n,.02*n))fire((f.Hit.p+Z)+b)else sp.Ammo.Value=sp.Ammo.Value-1 local K=sp.Handle.CFrame*BarrlePos local k=(f.Hit.p-K).magnitude local Z=Vector3.new(math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k),math.random(-(Spread/10)*k,(Spread/10)*k))fire(f.Hit.p+Z)end wait(Firerate)if not automatic then break end end enabled=true else sp.Handle.Trigger:Play()end end function onEquippedLocal(f)if f==nil then print("\077\111\117\115\101 \110\111\116 \102\111\117\110\100")return end f.Icon=Cursors[1]f.KeyDown:connect(function(K)onKeyDown(K,f)end)f.Button1Down:connect(function()onButton1Down(f)end)f.Button1Up:connect(function()onButton1Up(f)end)check()equiped=true if#Cursors>1 then while equiped do t=r.Stepped:wait()local K=sp.Parent:FindFirstChild("\080\111\115\101")if K~=nil then if sp.Parent.Pose.Value=="\083\116\097\110\100\105\110\103"then Spread=MinSpread else Spread=MinSpread+.1*(MaxSpread-MinSpread)end else Spread=MinSpread end if t-last<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if t-last2<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if t-last3<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if t-last4<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if t-last5<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if t-last6<SpreadRate then Spread=Spread+.1*(MaxSpread-MinSpread)end if not reloading then local K=(Spread-MinSpread)/(MaxSpread-MinSpread)for k=0,#Cursors-1,1 do if K>k/(#Cursors-1)-(1/(#Cursors-1))/2 and K<k/(#Cursors-1)+(1/(#Cursors-1))/2 then f.Icon=Cursors[k+1]end end end wait(Firerate*.9)end end end function onUnequippedLocal(f)equiped=false reloading=false end sp.Equipped:connect(onEquippedLocal)sp.Unequipped:connect(onUnequippedLocal)check()
-------------------------------------------------------------------------------

function tagHumanoid(humanoid)
	local plr = game.Players:playerFromCharacter(sp.Parent)
	if plr ~= nil then
		local tag = Instance.new("ObjectValue")
		tag.Value = plr
		tag.Name = "creator"
		tag.Parent = humanoid
		delay(2, function()
			if tag ~= nil then
				tag.Parent = nil
			end
		end)
	end
end

function reload(mouse)
	reloading = true
	mouse.Icon = ReloadCursor
	while sp.Ammo.Value < ClipSize and reloading and enabled do
		wait(ReloadTime / ClipSize)
		if reloading then
			sp.Ammo.Value = sp.Ammo.Value + 1
			check()
		else
			break
		end
	end
	check()
	mouse.Icon = Cursors[1]
	reloading = false
end

function onKeyDown(key, mouse)
	key = key:lower()
	if key == "r" and not reloading then
		reload(mouse)
	end
end

function movecframe(p, pos)
	p.Parent = game.Lighting
	p.Position = pos
	p.Parent = game.Workspace
end

function fire(aim)
	sp.Handle.Fire:Play()

	t = r.Stepped:wait()
	last6 = last5
	last5 = last4
	last4 = last3
	last3 = last2
	last2 = last
	last = t

	local bullet = Bullet:clone()
	local bt2 = game.Lighting.BulletTexture:clone()
	bt2.BrickColor = BrickColor.new("Bright red")
	bt2.Mesh.Scale = Vector3.new(0.5, 0.5, 2)
	local totalDist = 0
	Lengthdist = -RayLength / 0.5
	local startpoint = sp.Handle.CFrame * BarrlePos
	local dir = aim - startpoint
	dir = computeDirection(dir)
	local cfrm = CFrame.new(startpoint, dir + startpoint)
	local hit, pos, normal, time = raycast(
		game.Workspace,
		startpoint,
		cfrm * Vector3.new(0, 0, Lengthdist) - startpoint,
		function(brick)
			if brick.Name == "Glass" then
				return true
			elseif brick.Name == "Bullet" or brick.Name == "BulletTexture" then
				return false
			elseif brick:IsDescendantOf(sp.Parent) then
				return false
			elseif brick.Name == "Handle" then
				if brick.Parent:IsDescendantOf(sp.Parent) then
					return false
				else
					return true
				end
			end
			return true
		end
	)
	bullet.Parent = game.Workspace
	bt2.Parent = game.Workspace
	if hit ~= nil then
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid ~= nil then
			local damage = math.random(BaseDamage - (BaseDamage * 0.25), BaseDamage + (BaseDamage * 0.25))
			if hit.Name == "Head" then
				damage = damage * 1.25
			elseif hit.Name == "Torso" then
			else
				damage = damage * 0.75
			end
			if humanoid.Health > 0 then
				local eplr = game.Players:playerFromCharacter(humanoid.Parent)
				local plr = game.Players:playerFromCharacter(sp.Parent)
				if eplr ~= nil and plr ~= nil then
					--	if eplr.TeamColor~=plr.TeamColor or eplr.Neutral or plr.Neutral then
					tagHumanoid(humanoid)
					humanoid:TakeDamage(damage)
				--	end
				else
					tagHumanoid(humanoid)
					humanoid:TakeDamage(damage)
				end
			end
		end
		if
			(hit.Name == "Part10")
			or (hit.Name == "Part11")
			or (hit.Name == "Part21")
			or (hit.Name == "Part23")
			or (hit.Name == "Part24")
			or (hit.Name == "Part8")
		then
			rand = math.random(1, 5)
			if rand == 1 then
				workspace.GlassSound:play()
				hit:breakJoints()
			end
		end
		if hit.Parent:findFirstChild("Hit") then
			hit.Parent.Health.Value = hit.Parent.Health.Value - BaseDamage / 3
		end
		distance = (startpoint - pos).magnitude
		bullet.CFrame = cfrm * CFrame.new(0, 0, -distance / 2)
		bullet.Mesh.Scale = Vector3.new(0.15, 0.15, distance)
	else
		bullet.CFrame = cfrm * CFrame.new(0, 0, -RayLength / 2)
		bullet.Mesh.Scale = Vector3.new(0.15, 0.15, RayLength)
	end
	if pos ~= nil then
		bt2.CFrame = bullet.CFrame
		movecframe(bt2, pos)
	end
	local deb = game:FindFirstChild("Debris")
	if deb == nil then
		local debris = Instance.new("Debris")
		debris.Parent = game
	end
	check()
	game.Debris:AddItem(bullet, 0.05)
	game.Debris:AddItem(bt2, 0.5)
end

function onButton1Up(mouse)
	down = false
end

function onButton1Down(mouse)
	h = sp.Parent:FindFirstChild("Humanoid")
	if not enabled or reloading or down or h == nil then
		return
	end
	if sp.Ammo.Value > 0 and h.Health > 0 then
		--[[if sp.Ammo.Value<=0 then
			if not reloading then
				reload(mouse)
			end
			return
		end]]
		down = true
		enabled = false
		while down do
			if sp.Ammo.Value <= 0 then
				break
			end
			if burst then
				local startpoint = sp.Handle.CFrame * BarrlePos
				local mag = (mouse.Hit.p - startpoint).magnitude
				local rndm = Vector3.new(
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag)
				)
				fire(mouse.Hit.p + rndm)
				sp.Ammo.Value = sp.Ammo.Value - 1
				if sp.Ammo.Value <= 0 then
					break
				end
				wait(0.05)
				local startpoint = sp.Handle.CFrame * BarrlePos
				local mag2 = ((mouse.Hit.p + rndm) - startpoint).magnitude
				local rndm2 = Vector3.new(
					math.random(-(0.1 / 10) * mag2, (0.1 / 10) * mag2),
					math.random(-(0.1 / 10) * mag2, (0.1 / 10) * mag2),
					math.random(-(0.1 / 10) * mag2, (0.1 / 10) * mag2)
				)
				fire(mouse.Hit.p + rndm + rndm2)
				sp.Ammo.Value = sp.Ammo.Value - 1
				if sp.Ammo.Value <= 0 then
					break
				end
				wait(0.05)
				fire(mouse.Hit.p + rndm + rndm2 + rndm2)
				sp.Ammo.Value = sp.Ammo.Value - 1
			elseif shot then
				sp.Ammo.Value = sp.Ammo.Value - 1
				local startpoint = sp.Handle.CFrame * BarrlePos
				local mag = (mouse.Hit.p - startpoint).magnitude
				local rndm = Vector3.new(
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag)
				)
				fire(mouse.Hit.p + rndm)
				local mag2 = ((mouse.Hit.p + rndm) - startpoint).magnitude
				local rndm2 = Vector3.new(
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2)
				)
				fire(mouse.Hit.p + rndm + rndm2)
				local rndm3 = Vector3.new(
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2)
				)
				fire(mouse.Hit.p + rndm + rndm3)
				local rndm4 = Vector3.new(
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2),
					math.random(-(0.2 / 10) * mag2, (0.2 / 10) * mag2)
				)
				fire(mouse.Hit.p + rndm + rndm4)
			else
				sp.Ammo.Value = sp.Ammo.Value - 1
				local startpoint = sp.Handle.CFrame * BarrlePos
				local mag = (mouse.Hit.p - startpoint).magnitude
				local rndm = Vector3.new(
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag),
					math.random(-(Spread / 10) * mag, (Spread / 10) * mag)
				)
				fire(mouse.Hit.p + rndm)
			end
			wait(Firerate)
			if not automatic then
				break
			end
		end
		enabled = true
	else
		sp.Handle.Trigger:Play()
	end
end

function onEquippedLocal(mouse)
	if mouse == nil then
		print("Mouse not found")
		return
	end
	mouse.Icon = Cursors[1]
	mouse.KeyDown:connect(function(key)
		onKeyDown(key, mouse)
	end)
	mouse.Button1Down:connect(function()
		onButton1Down(mouse)
	end)
	mouse.Button1Up:connect(function()
		onButton1Up(mouse)
	end)
	check()
	equiped = true
	if #Cursors > 1 then
		while equiped do
			t = r.Stepped:wait()
			local action = sp.Parent:FindFirstChild("Pose")
			if action ~= nil then
				if sp.Parent.Pose.Value == "Standing" then
					Spread = MinSpread
				else
					Spread = MinSpread + ((1 / 10) * (MaxSpread - MinSpread))
				end
			else
				Spread = MinSpread
			end
			if t - last < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if t - last2 < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if t - last3 < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if t - last4 < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if t - last5 < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if t - last6 < SpreadRate then
				Spread = Spread + 0.1 * (MaxSpread - MinSpread)
			end
			if not reloading then
				local percent = (Spread - MinSpread) / (MaxSpread - MinSpread)
				for i = 0, #Cursors - 1 do
					if
						percent > (i / (#Cursors - 1)) - ((1 / (#Cursors - 1)) / 2)
						and percent < (i / (#Cursors - 1)) + ((1 / (#Cursors - 1)) / 2)
					then
						mouse.Icon = Cursors[i + 1]
					end
				end
			end
			wait(Firerate * 0.9)
		end
	end
end
function onUnequippedLocal(mouse)
	equiped = false
	reloading = false
end
sp.Equipped:connect(onEquippedLocal)
sp.Unequipped:connect(onUnequippedLocal)
check()
