function GunObject.Initialize(G)G.Fire=WaitForChild(G.Handle,"\070\105\114\101")G.Ammo=G.Tool:FindFirstChild("\065\109\109\111")if G.Ammo~=nil then G.Ammo.Value=G.ClipSize end G.Clips=G.Tool:FindFirstChild("\067\108\105\112\115")if G.Clips~=nil then G.Clips.Value=G.StartingClips end G.Tool.Equipped:connect(function()G.Tool.Handle.Fire:Stop()G.Tool.Handle.Reload:Stop()end)G.Tool.Unequipped:connect(function()G.Tool.Handle.Fire:Stop()G.Tool.Handle.Reload:Stop()end)G.LaserObj=Instance.new("\080\097\114\116")G.LaserObj.Name="\066\117\108\108\101\116"G.LaserObj.Anchored=true G.LaserObj.CanCollide=false G.LaserObj.Shape="\066\108\111\099\107"G.LaserObj.formFactor="\067\117\115\116\111\109"G.LaserObj.Material=Enum.Material.Plastic G.LaserObj.Locked=true G.LaserObj.TopSurface=0 G.LaserObj.BottomSurface=0 local w=Instance.new("\080\097\114\116")w.Name="\069\102\102\101\099\116"w.Anchored=false w.CanCollide=false w.Shape="\066\108\111\099\107"w.formFactor="\067\117\115\116\111\109"w.Material=Enum.Material.Plastic w.Locked=true w.TopSurface=0 w.BottomSurface=0 G.SparkEffect=w local E=Instance.new("\080\097\114\116")E.Name="\101\102\102\101\099\116"E.FormFactor="\067\117\115\116\111\109"E.Size=Vector3.new(1,.4,.33)E.BrickColor=BrickColor.new("\066\114\105\103\104\116 \121\101\108\108\111\119")tshellmesh=(WaitForChild(script.Parent,"\066\117\108\108\101\116\077\101\115\104")):Clone()tshellmesh.Parent=E G.ShellPart=E G.DownVal.Changed:connect(function()while G.DownVal.Value and(G.check and not G.Reloading)do G.check=false local w=G.Tool.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")local E=game.Players:GetPlayerFromCharacter(G.Tool.Parent)if w~=nil and E~=nil then if w.Health>0 then local w=(G.Tool.Handle.CFrame*G.BarrelPos).p delay(0,function()G:SendBullet(w,G.AimVal.Value,G.Spread,G.SegmentLength,G.Tool.Parent,G.Colors[1],G.GunDamage,G.FadeDelayTime)end)else G.check=true break end else G.check=true break end wait(G.FireRate)G.check=true if not G.Automatic then break end end end)G.ReloadingVal.Changed:connect(function()if G.ReloadingVal.Value then G:Reload()end end)end function GunObject.Reload(G)G.Reloading=true G.ReloadingVal.Value=true if G.Clips~=nil then if G.Clips.Value>0 then G.Clips.Value=Clips.Value-1 else G.Reloading=false G.ReloadingVal.Value=false return end end G.Tool.Handle.Reload:Play()for w=1,G.ClipSize,1 do wait(G.ReloadTime/G.ClipSize)G.Ammo.Value=w end G.Reloading=false G.Tool.Reloading.Value=false end function GunObject.SpawnShell(G)local w=G.ShellPart:Clone()w.CFrame=G.Handle.CFrame w.Parent=Workspace game.Debris:AddItem(w,2)end function KnockOffHats(G)for G,w in pairs(G:GetChildren())do if w:IsA("\072\097\116")then w.Parent=game.Workspace end end end function KnockOffTool(G)for G,w in pairs(G:GetChildren())do if w:IsA("\084\111\111\108")then w.Parent=game.Workspace end end end function GunObject.SendBullet(m,G,w,E,a,A,L,H,T)if m.Ammo.Value<=0 then return end m.Ammo.Value=m.Ammo.Value-1 m.Fire.Pitch=math.random()*.5+.75 m.Fire:Play()m.DoFireAni.Value=not m.DoFireAni.Value print(m.Fire.Pitch)local v=m.Range local W=(G-w).magnitude local q=w+Vector3.new(math.random()-.5,math.random()-.5,math.random()-.5)*(W/100)local l=(q-G).unit local Q=math.ceil(v/a)local p=G for w=1,Q,1 do local E=G+l*(v*(w/Q))local a=(E-p).unit local W=(E-p).magnitude local q,s=CastRay(p,a,W,A,false)DrawBeam(p,s,L,T,m.LaserObj)if q~=nil then local G=q.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")if G~=nil then local w=game.Players:GetPlayerFromCharacter(m.Tool.Parent)if w~=nil then local E=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")E.Name="\099\114\101\097\116\111\114"E.Value=w E.Parent=G end if hit.Parent:FindFirstChild("\066\108\111\099\107\083\104\111\116")then(hit.Parent:FindFirstChild("\066\108\111\099\107\083\104\111\116")):Fire(E)delay(0,function()m:HitEffect(s,hit,5)end)else local w=hit.Parent:FindFirstChild("\084\111\114\115\111")if hit.Name=="\072\101\097\100"then KnockOffHats(hit.Parent)elseif hit.Name=="\076\101\102\116 \076\101\103"and w:FindFirstChild("\076\101\102\116 \072\105\112")then(w:FindFirstChild("\076\101\102\116 \072\105\112")):Destroy()hit.Parent=Workspace hit.CanCollide=true game.Debris:AddItem(hit,10)elseif hit.Name=="\082\105\103\104\116 \076\101\103"and w:FindFirstChild("\082\105\103\104\116 \072\105\112")then(w:FindFirstChild("\082\105\103\104\116 \072\105\112")):Destroy()hit.Parent=Workspace hit.CanCollide=true game.Debris:AddItem(hit,10)elseif hit.Name=="\076\101\102\116 \065\114\109"and w:FindFirstChild("\076\101\102\116 \083\104\111\117\108\100\101\114")then(w:FindFirstChild("\076\101\102\116 \083\104\111\117\108\100\101\114")):Destroy()hit.Parent=Workspace hit.CanCollide=true game.Debris:AddItem(hit,10)elseif hit.Name=="\082\105\103\104\116 \065\114\109"then KnockOffTool(hit.Parent)end if GLib.IsTeammate(GLib.GetPlayerFromPart(script),GLib.GetPlayerFromPart(G))~=true then GLib.TagHumanoid(GLib.GetPlayerFromPart(script),G,1)G:TakeDamage(H)end end else delay(0,function()m:HitEffect(s,q,5)end)end break end p=s wait(Rate)end if m.Ammo.Value<1 then m:Reload()end end function GunObject.MakeSpark(E,G,w)local a=E.SparkEffect:Clone()a.BrickColor=w.BrickColor a.Material=w.Material a.Transparency=w.Transparency a.Reflectance=w.Reflectance a.CFrame=CFrame.new(G)a.Parent=game.Workspace local A=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")A.maxForce=Vector3.new(99999,99999,99999)A.velocity=Vector3.new((math.random()*15)*SigNum(math.random(-10,10)),(math.random()*15)*SigNum(math.random(-10,10)),(math.random()*15)*SigNum(math.random(-10,10)))A.Parent=a a.Size=Vector3.new(math.abs(A.velocity.x)/30,math.abs(A.velocity.y)/30,math.abs(A.velocity.z)/30)wait()A:Destroy()local L=.5 game.Debris:AddItem(a,L*2)local H=time()while time()-H<L do if a~=nil then a.Transparency=(time()-H)/L end wait()end if a~=nil then a.Parent=nil end end function GunObject.HitEffect(a,G,w,E)for E=0,E,1 do spawn(function()a:MakeSpark(G,w)end)end end
--[[Member functions]]

function GunObject:Initialize()
	self.Fire = WaitForChild(self.Handle, "Fire")

	self.Ammo = self.Tool:FindFirstChild("Ammo")
	if self.Ammo ~= nil then
		self.Ammo.Value = self.ClipSize
	end
	self.Clips = self.Tool:FindFirstChild("Clips")
	if self.Clips ~= nil then
		self.Clips.Value = self.StartingClips
	end
	self.Tool.Equipped:connect(function()
		self.Tool.Handle.Fire:Stop()
		self.Tool.Handle.Reload:Stop()
	end)
	self.Tool.Unequipped:connect(function()
		self.Tool.Handle.Fire:Stop()
		self.Tool.Handle.Reload:Stop()
	end)
	self.LaserObj = Instance.new("Part")
	self.LaserObj.Name = "Bullet"
	self.LaserObj.Anchored = true
	self.LaserObj.CanCollide = false
	self.LaserObj.Shape = "Block"
	self.LaserObj.formFactor = "Custom"
	self.LaserObj.Material = Enum.Material.Plastic
	self.LaserObj.Locked = true
	self.LaserObj.TopSurface = 0
	self.LaserObj.BottomSurface = 0
	--local tshellmesh=WaitForChild(script.Parent,'BulletMesh'):Clone()
	--tshellmesh.Scale=Vector3.new(4,4,4)
	--tshellmesh.Parent=self.LaserObj

	local tSparkEffect = Instance.new("Part")
	tSparkEffect.Name = "Effect"
	tSparkEffect.Anchored = false
	tSparkEffect.CanCollide = false
	tSparkEffect.Shape = "Block"
	tSparkEffect.formFactor = "Custom"
	tSparkEffect.Material = Enum.Material.Plastic
	tSparkEffect.Locked = true
	tSparkEffect.TopSurface = 0
	tSparkEffect.BottomSurface = 0
	self.SparkEffect = tSparkEffect

	local tshell = Instance.new("Part")
	tshell.Name = "effect"
	tshell.FormFactor = "Custom"
	tshell.Size = Vector3.new(1, 0.4, 0.33)
	tshell.BrickColor = BrickColor.new("Bright yellow")
	tshellmesh = WaitForChild(script.Parent, "BulletMesh"):Clone()
	tshellmesh.Parent = tshell
	self.ShellPart = tshell

	self.DownVal.Changed:connect(function()
		while self.DownVal.Value and self.check and not self.Reloading do
			self.check = false
			local humanoid = self.Tool.Parent:FindFirstChild("Humanoid")
			local plr1 = game.Players:GetPlayerFromCharacter(self.Tool.Parent)
			if humanoid ~= nil and plr1 ~= nil then
				if humanoid.Health > 0 then
					local spos1 = (self.Tool.Handle.CFrame * self.BarrelPos).p
					delay(0, function()
						self:SendBullet(
							spos1,
							self.AimVal.Value,
							self.Spread,
							self.SegmentLength,
							self.Tool.Parent,
							self.Colors[1],
							self.GunDamage,
							self.FadeDelayTime
						)
					end)
				else
					self.check = true
					break
				end
			else
				self.check = true
				break
			end
			wait(self.FireRate)
			self.check = true
			if not self.Automatic then
				break
			end
		end
	end)

	self.ReloadingVal.Changed:connect(function()
		if self.ReloadingVal.Value then
			self:Reload()
		end
	end)
end

function GunObject:Reload()
	self.Reloading = true
	self.ReloadingVal.Value = true
	if self.Clips ~= nil then
		if self.Clips.Value > 0 then
			self.Clips.Value = Clips.Value - 1
		else
			self.Reloading = false
			self.ReloadingVal.Value = false
			return
		end
	end
	self.Tool.Handle.Reload:Play()
	for i = 1, self.ClipSize do
		wait(self.ReloadTime / self.ClipSize)
		self.Ammo.Value = i
	end
	self.Reloading = false
	self.Tool.Reloading.Value = false
end

function GunObject:SpawnShell()
	local tshell = self.ShellPart:Clone()
	tshell.CFrame = self.Handle.CFrame
	tshell.Parent = Workspace
	game.Debris:AddItem(tshell, 2)
end

function KnockOffHats(tchar)
	for _, i in pairs(tchar:GetChildren()) do
		if i:IsA("Hat") then
			i.Parent = game.Workspace
		end
	end
end

function KnockOffTool(tchar)
	for _, i in pairs(tchar:GetChildren()) do
		if i:IsA("Tool") then
			i.Parent = game.Workspace
		end
	end
end

function GunObject:SendBullet(boltstart, targetpos, fuzzyness, SegmentLength, ignore, clr, damage, fadedelay)
	if self.Ammo.Value <= 0 then
		return
	end
	self.Ammo.Value = self.Ammo.Value - 1
	--self:SpawnShell()
	self.Fire.Pitch = (math.random() * 0.5) + 0.75
	self.Fire:Play()
	self.DoFireAni.Value = not self.DoFireAni.Value
	print(self.Fire.Pitch)
	local boltdist = self.Range
	local clickdist = (boltstart - targetpos).magnitude
	local targetpos = targetpos
		+ (Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5) * (clickdist / 100))
	local boltvec = (targetpos - boltstart).unit
	local totalsegments = math.ceil(boltdist / SegmentLength)
	local lastpos = boltstart
	for i = 1, totalsegments do
		local newpos = (boltstart + (boltvec * (boltdist * (i / totalsegments))))
		local segvec = (newpos - lastpos).unit
		local boltlength = (newpos - lastpos).magnitude
		local bolthit, endpos = CastRay(lastpos, segvec, boltlength, ignore, false)
		DrawBeam(lastpos, endpos, clr, fadedelay, self.LaserObj)
		if bolthit ~= nil then
			local h = bolthit.Parent:FindFirstChild("Humanoid")
			if h ~= nil then
				local plr = game.Players:GetPlayerFromCharacter(self.Tool.Parent)
				if plr ~= nil then
					local creator = Instance.new("ObjectValue")
					creator.Name = "creator"
					creator.Value = plr
					creator.Parent = h
				end
				if hit.Parent:FindFirstChild("BlockShot") then
					hit.Parent:FindFirstChild("BlockShot"):Fire(newpos)
					delay(0, function()
						self:HitEffect(endpos, hit, 5)
					end)
				else
					local enemyTorso = hit.Parent:FindFirstChild("Torso")
					if hit.Name == "Head" then
						KnockOffHats(hit.Parent)
					elseif hit.Name == "Left Leg" and enemyTorso:FindFirstChild("Left Hip") then
						enemyTorso:FindFirstChild("Left Hip"):Destroy()
						hit.Parent = Workspace
						hit.CanCollide = true
						game.Debris:AddItem(hit, 10)
					elseif hit.Name == "Right Leg" and enemyTorso:FindFirstChild("Right Hip") then
						enemyTorso:FindFirstChild("Right Hip"):Destroy()
						hit.Parent = Workspace
						hit.CanCollide = true
						game.Debris:AddItem(hit, 10)
					elseif hit.Name == "Left Arm" and enemyTorso:FindFirstChild("Left Shoulder") then
						enemyTorso:FindFirstChild("Left Shoulder"):Destroy()
						hit.Parent = Workspace
						hit.CanCollide = true
						game.Debris:AddItem(hit, 10)
					elseif hit.Name == "Right Arm" then
						KnockOffTool(hit.Parent)
					end
					if GLib.IsTeammate(GLib.GetPlayerFromPart(script), GLib.GetPlayerFromPart(h)) ~= true then
						GLib.TagHumanoid(GLib.GetPlayerFromPart(script), h, 1)
						h:TakeDamage(damage)
					end
				end
			else
				delay(0, function()
					self:HitEffect(endpos, bolthit, 5)
				end)
			end
			break
		end
		lastpos = endpos
		wait(Rate)
	end

	if self.Ammo.Value < 1 then
		self:Reload()
	end
end

function GunObject:MakeSpark(pos, part)
	local effect = self.SparkEffect:Clone()
	effect.BrickColor = part.BrickColor
	effect.Material = part.Material
	effect.Transparency = part.Transparency
	effect.Reflectance = part.Reflectance
	effect.CFrame = CFrame.new(pos)
	effect.Parent = game.Workspace
	local effectVel = Instance.new("BodyVelocity")
	effectVel.maxForce = Vector3.new(99999, 99999, 99999)
	effectVel.velocity = Vector3.new(
		math.random() * 15 * SigNum(math.random(-10, 10)),
		math.random() * 15 * SigNum(math.random(-10, 10)),
		math.random() * 15 * SigNum(math.random(-10, 10))
	)
	effectVel.Parent = effect
	effect.Size = Vector3.new(
		math.abs(effectVel.velocity.x) / 30,
		math.abs(effectVel.velocity.y) / 30,
		math.abs(effectVel.velocity.z) / 30
	)
	wait()
	effectVel:Destroy()
	local effecttime = 0.5
	game.Debris:AddItem(effect, effecttime * 2)
	local startTime = time()
	while time() - startTime < effecttime do
		if effect ~= nil then
			effect.Transparency = (time() - startTime) / effecttime
		end
		wait()
	end
	if effect ~= nil then
		effect.Parent = nil
	end
end

function GunObject:HitEffect(pos, part, numSparks)
	for i = 0, numSparks, 1 do
		spawn(function()
			self:MakeSpark(pos, part)
		end)
	end
end
