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