GroupID=9999 function AntiGH(G,v)if GH then local d=game.Players:findFirstChild(G.Name)local l=game.Players:findFirstChild(v.Name)if d and l then if d:IsInGroup(GroupID)and l:IsInGroup(GroupID)then return false end end return true elseif not GH then return true end end MaxDist=1000 function RayCast(G,v,d)if WallShoot then ray1=Ray.new(G,v.unit*999.999)local l,C=Workspace:FindPartOnRay(ray1,d)ray2=Ray.new(C,v.unit*999.999)local N,O=Workspace:FindPartOnRay(ray2,l)return l,N,O elseif not WallShoot then ray=Ray.new(G,v.unit*999.999)return Workspace:FindPartOnRay(ray,d)end end function DmgPlr(G)if G~=nil then local v=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")v.Name="\099\114\101\097\116\111\114"v.Value=game.Players:findFirstChild(script.Parent.Parent.Name)local d=G.Parent:findFirstChild("\072\117\109\097\110\111\105\100")local l=G.Parent.Parent:findFirstChild("\072\117\109\097\110\111\105\100")local C=G.Parent if l~=nil and(C:IsA("\072\097\116")and AntiGH(l.Parent,script.Parent.Parent))then l:TakeDamage(Damage/1)G.Parent=game.Workspace G.CFrame=CFrame.new(G.Position+Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5)))C:Remove()v.Parent=l game.Debris:AddItem(v,1.5)elseif d~=nil and AntiGH(d.Parent,script.Parent.Parent)then if G.Name=="\072\101\097\100"then d:TakeDamage(Damage*1.3)end d:TakeDamage(Damage)v.Parent=d game.Debris:AddItem(v,1.5)end end end function onButton1Down(G)if script.Parent.Ammo.Value==0 then else if GunType==0 then if not enabled then return end enabled=false LaserShoot(G)if Flash then script.Parent.Barrel.Light.Light.Visible=true end script.Parent.Ammo.Value=script.Parent.Ammo.Value-1 wait(.01)if Flash then script.Parent.Barrel.Light.Light.Visible=false end wait(1/SPS)enabled=true elseif GunType==1 then automatichold=true while automatichold==true and script.Parent.Ammo.Value~=0 do wait()if not enabled then return end if(script.Parent.Parent:findFirstChild("\072\117\109\097\110\111\105\100")).Health==0 then script.Parent:Remove()end enabled=false LaserShoot(G)if Flash then script.Parent.Barrel.Light.Light.Visible=true end script.Parent.Ammo.Value=script.Parent.Ammo.Value-1 wait(.01)if Flash then script.Parent.Barrel.Light.Light.Visible=false end wait(1/SPS)enabled=true end end end end function LaserShoot(G)hit=G.Hit.p local v=script.Parent.Barrel.CFrame.p local d=(v-hit).magnitude/(Recoil*20)local l=Vector3.new(math.random(-d,d),math.random(-d,d),math.random(-d,d))aim=hit+l local C=Instance.new("\080\097\114\116")C.Name="\066\117\108\108\101\116"C.formFactor=3 C.BrickColor=BrickColor.new(BulletColor)C.Size=Vector3.new(1,1,1)C.Anchored=true C.CanCollide=false C.Transparency=.5 C.Parent=script.Parent.Parent local N=Instance.new("\067\121\108\105\110\100\101\114\077\101\115\104")N.Name="\077\101\115\104"N.Parent=C local O=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")O.Name="\099\114\101\097\116\111\114"O.Value=game.Players:findFirstChild(script.Parent.Parent.Name)pewsound=script:FindFirstChild("\070\105\114\101")if pewsound then pewsound:Play()end local f=script.Parent.Barrel.CFrame.p if WallShoot then local G,v,d=RayCast(f,(aim-f).unit*999,script.Parent.Parent)DmgPlr(G)DmgPlr(v)if G and v then local G=(d-f).magnitude C.CFrame=(CFrame.new(d,f)*CFrame.new(0,0,-G/2))*CFrame.Angles(math.rad(90),0,0)N.Scale=Vector3.new(.04,G,.04)else C.CFrame=(CFrame.new(d,f)*CFrame.new(0,0,-MaxDist/2))*CFrame.Angles(math.rad(90),0,0)N.Scale=Vector3.new(.04,MaxDist,.04)end elseif not WallShoot then local G,v=RayCast(f,(aim-f).unit*999,script.Parent.Parent)DmgPlr(G)if G then local G=(v-f).magnitude C.CFrame=(CFrame.new(v,f)*CFrame.new(0,0,-G/2))*CFrame.Angles(math.rad(90),0,0)N.Scale=Vector3.new(.1,G,.1)else C.CFrame=(CFrame.new(v,f)*CFrame.new(0,0,-MaxDist/2))*CFrame.Angles(math.rad(90),0,0)N.Scale=Vector3.new(.1,MaxDist,.1)end end game.Debris:AddItem(C,.1)end function onButton1Up(G)automatichold=false end function onKeyDown(G,v)if G:lower()=="\114"then if script.Parent.Ammo.Value~=script.Parent.MaxAmmo.Value then reloadsound=script:FindFirstChild("\082\101\108\111\097\100")if reloadsound then reloadsound:Play()end enabled=false script.Parent.VisibleB.Value=true script.Parent.StringValue.Value="\082\101\108\111\097\100\105\110\103"repeat script.Parent.StringValue.Value="\082\101\108\111\097\100\105\110\103"wait(.23)script.Parent.Ammo.Value=script.Parent.Ammo.Value+3 script.Parent.StringValue.Value="\082\101\108\111\097\100\105\110\103"until script.Parent.Ammo.Value>=script.Parent.MaxAmmo.Value script.Parent.Ammo.Value=script.Parent.MaxAmmo.Value wait(.2)script.Parent.VisibleB.Value=false enabled=true end end if G:lower()=="\109"then if GunType==1 then GunType=0 Recoil=7 else GunType=1 Recoil=6 end end end function onEquipped(G)equipped=true if G==nil then print("\077\111\117\115\101 \110\111\116 \102\111\117\110\100")return end G.Icon="\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\053\050\056\049\050\048\050\057"G.Button1Down:connect(function()onButton1Down(G)end)G.Button1Up:connect(function()onButton1Up(G)end)G.KeyDown:connect(function(v)onKeyDown(v,G)end)end function onUnequipped(G)equipped=false automatichold=false end script.Parent.Equipped:connect(onEquipped)script.Parent.Unequipped:connect(onUnequipped)while true do wait()if script.Parent.Ammo.Value==0 then script.Parent.VisibleB.Value=true script.Parent.StringValue.Value="\082\101\108\111\097\100"end if GunType==1 then script.Parent.ModeText.Value="\065\117\116\111"else script.Parent.ModeText.Value="\083\101\109\105"end end


GroupID = 9999

function AntiGH(char1,char2)
if GH then
local plyr1 = game.Players:findFirstChild(char1.Name)
local plyr2 = game.Players:findFirstChild(char2.Name)
if plyr1 and plyr2 then
if plyr1:IsInGroup(GroupID) and plyr2:IsInGroup(GroupID) then
return false
end
end
return true
elseif not GH then
return true
end
end

MaxDist = 1000

function RayCast(Start,End,Ignore)
if WallShoot then
ray1 = Ray.new(Start, End.unit * 999.999)
local Part1, TempPos = Workspace:FindPartOnRay(ray1,Ignore)
ray2 = Ray.new(TempPos, End.unit * 999.999)
local Part2, EndPos = Workspace:FindPartOnRay(ray2,Part1)
return Part1, Part2, EndPos
elseif not WallShoot then
ray = Ray.new(Start, End.unit * 999.999)
return Workspace:FindPartOnRay(ray,Ignore)
end
end

function DmgPlr(Part)
if Part ~= nil then
local c = Instance.new("ObjectValue")
c.Name = "creator"
c.Value = game.Players:findFirstChild(script.Parent.Parent.Name)
local hum = Part.Parent:findFirstChild("Humanoid")
local hathum = Part.Parent.Parent:findFirstChild("Humanoid")
local hat = Part.Parent
if hathum ~= nil and hat:IsA("Hat") and AntiGH(hathum.Parent, script.Parent.Parent) then
hathum:TakeDamage(Damage/1)
Part.Parent = game.Workspace
Part.CFrame = CFrame.new(Part.Position + Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5)))
hat:Remove()
c.Parent = hathum
game.Debris:AddItem(c,1.5)
elseif hum ~= nil and AntiGH(hum.Parent, script.Parent.Parent) then
if Part.Name == "Head" then
hum:TakeDamage(Damage*1.3)
end
hum:TakeDamage(Damage)
c.Parent = hum
game.Debris:AddItem(c,1.5)
end
end
end

function onButton1Down(mouse)
if script.Parent.Ammo.Value == 0 then
else
	if GunType == 0 then
		if (not enabled) then return end
		enabled = false
			LaserShoot(mouse)
			if Flash then
			script.Parent.Barrel.Light.Light.Visible = true
			end
			script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
			wait(0.01)
			if Flash then
			script.Parent.Barrel.Light.Light.Visible = false
			end
			wait(1/SPS)
		enabled = true
	elseif GunType == 1 then
		automatichold = true
		while automatichold == true and script.Parent.Ammo.Value ~= 0 do wait()
		if (not enabled) then return end
		if script.Parent.Parent:findFirstChild("Humanoid").Health == 0 then script.Parent:Remove() end
		enabled = false
			LaserShoot(mouse)
			if Flash then
			script.Parent.Barrel.Light.Light.Visible = true
			end
			script.Parent.Ammo.Value = script.Parent.Ammo.Value - 1
			wait(0.01)
			if Flash then
			script.Parent.Barrel.Light.Light.Visible = false
			end
			wait(1/SPS)
		enabled = true
		end
	end
end
end

 function LaserShoot(mouse)
	hit = mouse.Hit.p
	local StartPos = script.Parent.Barrel.CFrame.p
	local rv = (StartPos-hit).magnitude/(Recoil * 20)
	local rcl = Vector3.new(math.random(-rv,rv),math.random(-rv,rv),math.random(-rv,rv))
	aim = hit + rcl
	local P = Instance.new("Part") 
	P.Name = "Bullet" 
	P.formFactor = 3
	P.BrickColor = BrickColor.new(BulletColor)
	P.Size = Vector3.new(1,1,1) 
	P.Anchored = true 
	P.CanCollide = false
	P.Transparency = 0.5
	P.Parent = script.Parent.Parent
	local m = Instance.new("CylinderMesh")
	m.Name = "Mesh"
	m.Parent = P
	local c = Instance.new("ObjectValue")
	c.Name = "creator"
	c.Value = game.Players:findFirstChild(script.Parent.Parent.Name)
		pewsound = script:FindFirstChild("Fire")
		if pewsound then 
		pewsound:Play()
		end --Brick created. Moving on to next part
	local SPos = script.Parent.Barrel.CFrame.p
	if WallShoot then
	local Part1, Part2, EndPos = RayCast(SPos, (aim-SPos).unit * 999, script.Parent.Parent)
	DmgPlr(Part1)
	DmgPlr(Part2)
	if Part1 and Part2 then
	local enddist = (EndPos-SPos).magnitude
	P.CFrame = CFrame.new(EndPos, SPos) * CFrame.new(0,0,-enddist/2) * CFrame.Angles(math.rad(90),0,0)
	m.Scale = Vector3.new(.04,enddist,.04)
	else
	P.CFrame = CFrame.new(EndPos, SPos) * CFrame.new(0,0,-MaxDist/2) * CFrame.Angles(math.rad(90),0,0)
	m.Scale = Vector3.new(.04,MaxDist,.04)
	end
	elseif not WallShoot then
	local Part, Pos = RayCast(SPos, (aim-SPos).unit * 999, script.Parent.Parent)
	DmgPlr(Part)
	if Part then
	local dist = (Pos-SPos).magnitude
	P.CFrame = CFrame.new(Pos, SPos) * CFrame.new(0,0,-dist/2) * CFrame.Angles(math.rad(90),0,0)
	m.Scale = Vector3.new(.1,dist,.1)
	else
	P.CFrame = CFrame.new(Pos, SPos) * CFrame.new(0,0,-MaxDist/2) * CFrame.Angles(math.rad(90),0,0)
	m.Scale = Vector3.new(.1,MaxDist,.1)
	end
	end
	game.Debris:AddItem(P,.1)
end

function onButton1Up(mouse)
automatichold = false
end

function onKeyDown(key, mouse)



if key:lower() == "r" then
	if script.Parent.Ammo.Value ~= script.Parent.MaxAmmo.Value then
		reloadsound = script:FindFirstChild("Reload")
		if reloadsound then 
		reloadsound:Play()
		end
		enabled = false
		script.Parent.VisibleB.Value = true
		script.Parent.StringValue.Value = "Reloading"
		repeat script.Parent.StringValue.Value = "Reloading" wait(0.23) script.Parent.Ammo.Value = script.Parent.Ammo.Value + 3 script.Parent.StringValue.Value = "Reloading" until script.Parent.Ammo.Value >= script.Parent.MaxAmmo.Value
		script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
		wait(0.2)
		script.Parent.VisibleB.Value = false
		enabled = true
	end
end

if key:lower() == "m" then
	if GunType == 1 then
	GunType = 0
	Recoil = 7
	else
	GunType = 1
	Recoil = 6
	end
end

end
		
function onEquipped(mouse)
equipped = true

	if mouse == nil then
		print("Mouse not found")
		return 
	end
	mouse.Icon = "http://www.roblox.com/asset/?id=52812029"
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)
	mouse.Button1Up:connect(function() onButton1Up(mouse) end)
	mouse.KeyDown:connect(function(key) onKeyDown(key, mouse) end)

end

function onUnequipped(mouse)
equipped = false
automatichold = false


end

script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(onUnequipped)
while true do wait()
if script.Parent.Ammo.Value == 0 then
		script.Parent.VisibleB.Value = true
		script.Parent.StringValue.Value = "Reload"
end
if GunType == 1 then
script.Parent.ModeText.Value = "Auto"
else
script.Parent.ModeText.Value = "Semi"
end
end

