local function U(U,H,X)if U then local r=H:FindFirstChild("\083\101\116\116\105\110\103")if H and r then local H=require(r)if CompareTables(X,H)==false then if KickPlayer then U:Kick("\089\111\117 \104\097\118\101 \098\101\101\110 \107\105\099\107\101\100 \097\110\100 \098\108\111\099\107\101\100 \102\114\111\109 \114\101\106\111\105\110\105\110\103 \116\104\105\115 \115\112\101\099\105\102\105\099 \115\101\114\118\101\114 \102\111\114 \101\120\112\108\111\105\116\105\110\103 \103\117\110 \115\116\097\116\115\046")warn(U.Name.." \104\097\115 \098\101\101\110 \107\105\099\107\101\100 \102\111\114 \101\120\112\108\111\105\116\105\110\103 \103\117\110 \115\116\097\116\115\046")table.insert(_G.TempBannedPlayers,U)else warn(U.Name.." - \080\111\116\101\110\116\105\097\108 \069\120\112\108\111\105\116\101\114 \066\121\112\097\115\115\033 \067\097\115\101 \050\058 \067\104\097\110\103\101\100 \071\117\110 \083\116\097\116\115 \070\114\111\109 \067\108\105\101\110\116")end return end else warn(U.Name.." - \080\111\116\101\110\116\105\097\108 \069\120\112\108\111\105\116\101\114 \066\121\112\097\115\115\033 \067\097\115\101 \049\058 \077\105\115\115\105\110\103 \071\117\110 \065\110\100 \077\111\100\117\108\101")return end else warn("\080\108\097\121\101\114 \100\111\101\115 \110\111\116 \101\120\105\115\116\046")return end end function _G.SecureSettings(H,X,r)U(H,X,r)end VisualizeHitEffect.OnServerEvent:Connect(function(U,H,X,r,m,i,D,...)local Q={...}if H=="\078\111\114\109\097\108"then for f,y in next,Players:GetPlayers()do if y~=U then VisualizeHitEffect:FireClient(y,H,X,r,m,i,D,Q[1],Q[2],Q[3],nil)end end elseif H=="\066\108\111\111\100"then for f,y in next,Players:GetPlayers()do if y~=U then VisualizeHitEffect:FireClient(y,H,X,r,m,i,D,Q[1],Q[2],nil)end end end end)VisualizeBullet.OnServerEvent:Connect(function(H,X,r,m,i,D,Q,f,y,J,O,p,j,g,W)U(H,r,X)for U,c in next,Players:GetPlayers()do if c~=H then VisualizeBullet:FireClient(c,X,r,m,i,D,Q,f,y,J,O,p,j,g,W)end end end)VisualizeMuzzle.OnServerEvent:Connect(function(U,H,X,r,m,i,D)for Q,f in next,Players:GetPlayers()do if f~=U then VisualizeMuzzle:FireClient(f,H,X,r,m,i,D)end end end)PlayAudio.OnServerEvent:Connect(function(U,H,X,r)for m,i in next,Players:GetPlayers()do if i~=U then PlayAudio:FireClient(i,H,X,r)end end end)ShatterGlass.OnServerEvent:Connect(function(U,H,X,r)if H then if H.Name=="\095\103\108\097\115\115"then if H.Transparency~=1 then if PhysicEffect then local U=Instance.new("\083\111\117\110\100")U.SoundId="\104\116\116\112\058\047\047\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\050\057\055\056\054\048\053\051\054\049"U.TimePosition=.1 U.Volume=1 U.Parent=H U:Play()U.Ended:Connect(function()U:Destroy()end)GlassShattering:Shatter(H,X,r+Vector3.new(math.random(-25,25),math.random(-25,25),math.random(-25,25)))else local U=Instance.new("\083\111\117\110\100")U.SoundId="\104\116\116\112\058\047\047\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061\050\057\055\056\054\048\053\051\054\049"U.TimePosition=.1 U.Volume=1 U.Parent=H U:Play()U.Ended:Connect(function()U:Destroy()end)local X=script.Shatter:Clone()X.Color=ColorSequence.new(H.Color)X.Transparency=NumberSequence.new({NumberSequenceKeypoint.new(0,H.Transparency),NumberSequenceKeypoint.new(1,1)})X.Parent=H task.delay(.01,function()X:Emit(10*math.abs(H.Size.magnitude))Debris:AddItem(X,X.Lifetime.Max)end)H.CanCollide=false H.Transparency=1 end end else error("\072\105\116 \112\097\114\116\'\115 \110\097\109\101 \109\117\115\116 \098\101 \'\095\103\108\097\115\115\'\046")end else error("\072\105\116 \112\097\114\116 \100\111\101\115\110\'\116 \101\120\105\115\116\046")end end)local function H(U,H,X,r)local m=X or 10000 local i=r or 1000 local D=m-i local Q=math.clamp(1-math.max(0,H-i)/math.max(1,D),0,1)return math.max(U*Q,0)end InflictTarget.OnServerInvoke=function(X,r,m,i,D,Q,f,y,J,O,p,j)U(X,m,r)local g if j and j[1]then local U=1-math.clamp(j[3]/j[2],0,1)g=j[4]and((O and(O.Name=="\072\101\097\100"and f[3]))and f[1]*f[2]or f[1])*U or(O and(O.Name=="\072\101\097\100"and f[3]))and f[1]*f[2]or f[1]else g=f[5]and H((O and(O.Name=="\072\101\097\100"and f[3]))and f[1]*f[2]or f[1],f[4],f[6],f[7])or(O and(O.Name=="\072\101\097\100"and f[3]))and f[1]*f[2]or f[1]end if D.Health-g<=0 and not D.Parent:FindFirstChild("\103\105\098\098\101\100")then if O then if O.Name=="\072\101\097\100"or O.Name=="\084\111\114\115\111"or O.Name=="\076\101\102\116 \065\114\109"or O.Name=="\082\105\103\104\116 \065\114\109"or O.Name=="\082\105\103\104\116 \076\101\103"or O.Name=="\076\101\102\116 \076\101\103"or O.Name=="\085\112\112\101\114\084\111\114\115\111"or O.Name=="\076\111\119\101\114\084\111\114\115\111"or O.Name=="\076\101\102\116\085\112\112\101\114\065\114\109"or O.Name=="\076\101\102\116\076\111\119\101\114\065\114\109"or O.Name=="\076\101\102\116\072\097\110\100"or O.Name=="\082\105\103\104\116\085\112\112\101\114\065\114\109"or O.Name=="\082\105\103\104\116\076\111\119\101\114\065\114\109"or O.Name=="\082\105\103\104\116\072\097\110\100"or O.Name=="\082\105\103\104\116\085\112\112\101\114\076\101\103"or O.Name=="\082\105\103\104\116\076\111\119\101\114\076\101\103"or O.Name=="\082\105\103\104\116\070\111\111\116"or O.Name=="\076\101\102\116\085\112\112\101\114\076\101\103"or O.Name=="\076\101\102\116\076\111\119\101\114\076\101\103"or O.Name=="\076\101\102\116\070\111\111\116"then VisualizeGore:FireAllClients(O,D.Parent,p)end end end if i then local U=D.Parent:FindFirstChild("\084\069\065\077")local H=m.Parent:FindFirstChild("\084\069\065\077")local X=(H and U)and U.Value~=H.Value or DamageModule.CanDamage(D.Parent,i)if j and(j[1]and j[5])then if D.Parent.Name==i.Name then X=D.Parent.Name==i.Name if j[7]then g=D:GetState()~=Enum.HumanoidStateType.Freefall and g or g*(1-j[6])else g=g*(1-j[6])end end end if D and(D.Health~=0 and(Q and X))then while D:FindFirstChild("\099\114\101\097\116\111\114")do D.creator:Destroy()end local U=Instance.new("\079\098\106\101\099\116\086\097\108\117\101",D)U.Name="\099\114\101\097\116\111\114"U.Value=i Debris:AddItem(U,5)if J[1]then local U=(Random.new()):NextInteger(0,100)if U<=J[2]then D:TakeDamage(math.abs(g*J[3]))else D:TakeDamage(math.abs(g))end else D:TakeDamage(math.abs(g))end if y[1]>0 then if not(j and(j[1]and j[5]))then local U=i.Character.HumanoidRootPart or i.Character.Head local H=.1 local X=y[1]/H local r=(Q.Position-U.Position).Unit*X local m=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121")m.MaxForce=Vector3.new(1000000000.0,1000000000.0,1000000000.0)m.Velocity=r m.Parent=Q Debris:AddItem(m,H)end end if y[2]>0 and(i.Character.Humanoid and i.Character.Humanoid.Health~=0)then if j and(j[1]and j[5])then if not D.Parent.Name==i.Name then i.Character.Humanoid.Health=i.Character.Humanoid.Health+g*y[2]end else i.Character.Humanoid.Health=i.Character.Humanoid.Health+g*y[2]end end if y[3]then local H=math.random(1,100)if H<=y[5]then if not D.Parent:FindFirstChild(y[4])then local H=((m:FindFirstChild("\071\117\110\083\099\114\105\112\116\095\083\101\114\118\101\114")):FindFirstChild(y[4])):Clone()H.creator.Value=U.Value H.Parent=D.Parent H.Disabled=false end end end end else warn("\085\110\097\098\108\101 \116\111 \114\101\103\105\115\116\101\114 \100\097\109\097\103\101 \098\101\099\097\117\115\101 \112\108\097\121\101\114 \105\115 \110\111 \108\111\110\103\101\114 \101\120\105\115\116\105\110\103 \104\101\114\101")end end Players.PlayerAdded:Connect(function(U)for H,X in pairs(_G.TempBannedPlayers)do if X==U.Name then U:Kick("\089\111\117 \099\097\110\110\111\116 \114\101\106\111\105\110 \097 \115\101\114\118\101\114 \119\104\101\114\101 \121\111\117 \119\101\114\101 \107\105\099\107\101\100 \102\114\111\109\046")warn(U.Name.." \116\114\105\101\100 \116\111 \114\101\106\111\105\110 \097 \115\101\114\118\101\114 \119\104\101\114\101 \104\101\047\115\104\101 \119\097\115 \107\105\099\107\101\100 \102\114\111\109\046")break end end end)

local function SecureSettings(Player, Gun, Module)
	if Player then
		local PreNewModule = Gun:FindFirstChild("Setting")
		if Gun and PreNewModule then
			local NewModule = require(PreNewModule)
			if (CompareTables(Module, NewModule) == false) then
				if KickPlayer then
					Player:Kick("You have been kicked and blocked from rejoining this specific server for exploiting gun stats.")
					warn(Player.Name.." has been kicked for exploiting gun stats.")
					table.insert(_G.TempBannedPlayers, Player)
				else
					warn(Player.Name.." - Potential Exploiter Bypass! Case 2: Changed Gun Stats From Client")	
				end
				return
			end
		else
		--[[if KickPlayer then
			Player:Kick("Gun and Module are not found. Kicked!")
			warn("Gun and Module are missing from "..Player.Name.."'s inventory.")
		else
			warn(Player.Name.." - Potential Exploiter Bypass! Case 1: Missing Gun And Module")	
		end]]
			warn(Player.Name.." - Potential Exploiter Bypass! Case 1: Missing Gun And Module")
			return
		end
	else
		warn("Player does not exist.")
		return
	end
end

function _G.SecureSettings(Player, Gun, Module)
	SecureSettings(Player, Gun, Module)
end

VisualizeHitEffect.OnServerEvent:Connect(function(Player, Type, Replicate, Hit, Position, Normal, Material, ...)
	local Table = {...}
	if Type == "Normal" then
		for _, plr in next, Players:GetPlayers() do
			if plr ~= Player then
				VisualizeHitEffect:FireClient(plr, Type, Replicate, Hit, Position, Normal, Material, Table[1], Table[2], Table[3], nil)
			end
		end
	elseif Type == "Blood" then
		for _, plr in next, Players:GetPlayers() do
			if plr ~= Player then
				VisualizeHitEffect:FireClient(plr, Type, Replicate, Hit, Position, Normal, Material, Table[1], Table[2], nil)
			end
		end
	end
end)

VisualizeBullet.OnServerEvent:Connect(function(Player, Module, Tool, Handle, VMHandle, CLDirections, SVDirections, FirePointObject, HitEffectData, BloodEffectData, BulletHoleData, ExplosiveData, BulletData, WhizData, ClientData)
	SecureSettings(Player, Tool, Module)	
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			VisualizeBullet:FireClient(plr, Module, Tool, Handle, VMHandle, CLDirections, SVDirections, FirePointObject, HitEffectData, BloodEffectData, BulletHoleData, ExplosiveData, BulletData, WhizData, ClientData)
		end
	end
end)

VisualizeMuzzle.OnServerEvent:Connect(function(Player, Handle, VMHandle, MuzzleFlashEnabled, MuzzleLightData, MuzzleEffect, Replicate)
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			VisualizeMuzzle:FireClient(plr, Handle, VMHandle, MuzzleFlashEnabled, MuzzleLightData, MuzzleEffect, Replicate)
		end
	end
end)

PlayAudio.OnServerEvent:Connect(function(Player, Audio, LowAmmoAudio, Replicate)
	for _, plr in next, Players:GetPlayers() do
		if plr ~= Player then
			PlayAudio:FireClient(plr, Audio, LowAmmoAudio, Replicate)
		end
	end
end)

ShatterGlass.OnServerEvent:Connect(function(Player, Hit, Pos, Dir)
	if Hit then
		if Hit.Name == "_glass" then
			if Hit.Transparency ~= 1 then
				if PhysicEffect then
					local Sound = Instance.new("Sound")
					Sound.SoundId = "http://roblox.com/asset/?id=2978605361"
					Sound.TimePosition = .1
					Sound.Volume = 1
					Sound.Parent = Hit
					Sound:Play()
					Sound.Ended:Connect(function()
						Sound:Destroy()
			        end)
					GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
					--[[local LifeTime = 5
					local FadeTime = 1
					local SX, SY, SZ = Hit.Size.X, Hit.Size.Y, Hit.Size.Z
					for X = 1, 4 do
						for Y = 1, 4 do
							local Part = Hit:Clone()
							local position = Vector3.new(X - 2.1, Y - 2.1, 0) * Vector3.new(SX / 4, SY / 4, SZ)
							local currentTransparency = Part.Transparency
							Part.Name = "_shatter"
							Part.Size = Vector3.new(SX / 4, SY / 4, SZ)
							Part.CFrame = Hit.CFrame * (CFrame.new(Part.Size / 8) - Hit.Size / 8 + position)			
							Part.Velocity = Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
							Part.Parent = workspace
							--Debris:AddItem(Part, 10)
							task.delay(LifeTime, function()
								if Part.Parent ~= nil then
									if LifeTime > 0 then
										local t0 = os.clock()
										while true do
											local Alpha = math.min((os.clock() - t0) / FadeTime, 1)
											Part.Transparency = Math.Lerp(currentTransparency, 1, Alpha)
							    			if Alpha == 1 then break end
						      				task.wait()
										end
										Part:Destroy()
									else
										Part:Destroy()
					    			end
								end
							end)
							Part.Anchored = false
						end
					end]]
				else
					local Sound = Instance.new("Sound")
					Sound.SoundId = "http://roblox.com/asset/?id=2978605361"
					Sound.TimePosition = .1
					Sound.Volume = 1
					Sound.Parent = Hit
					Sound:Play()
					Sound.Ended:Connect(function()
						Sound:Destroy()
			        end)
					local Particle = script.Shatter:Clone()
					Particle.Color = ColorSequence.new(Hit.Color)
					Particle.Transparency = NumberSequence.new{
						NumberSequenceKeypoint.new(0, Hit.Transparency), --(time, value)
						NumberSequenceKeypoint.new(1, 1)
					}
					Particle.Parent = Hit
					task.delay(0.01, function()
						Particle:Emit(10 * math.abs(Hit.Size.magnitude))
						Debris:AddItem(Particle, Particle.Lifetime.Max)
					end)
					Hit.CanCollide = false
					Hit.Transparency = 1
				end
			end
		else
			error("Hit part's name must be '_glass'.")
		end
	else
		error("Hit part doesn't exist.")
	end
end)

local function CalculateDamage(Damage, TravelDistance, ZeroDamageDistance, FullDamageDistance)
	local ZeroDamageDistance = ZeroDamageDistance or 10000
	local FullDamageDistance = FullDamageDistance or 1000
	local DistRange = ZeroDamageDistance - FullDamageDistance
	local FallOff = math.clamp(1 - (math.max(0, TravelDistance - FullDamageDistance) / math.max(1, DistRange)), 0, 1)
	return math.max(Damage * FallOff, 0)
end

InflictTarget.OnServerInvoke = function(Player, Module, Tool, Tagger, TargetHumanoid, TargetTorso, Damage, Misc, Critical, Hit, GoreData, ExplosiveData)
	SecureSettings(Player, Tool, Module) --Second layer
	local TrueDamage
	if ExplosiveData and ExplosiveData[1] then
		local DamageMultiplier = (1 - math.clamp((ExplosiveData[3] / ExplosiveData[2]), 0, 1))		
		TrueDamage = ExplosiveData[4] and ((Hit and Hit.Name == "Head" and Damage[3]) and Damage[1] * Damage[2] or Damage[1]) * DamageMultiplier or (Hit and Hit.Name == "Head" and Damage[3]) and Damage[1] * Damage[2] or Damage[1]
	else
		TrueDamage = Damage[5] and CalculateDamage((Hit and Hit.Name == "Head" and Damage[3]) and Damage[1] * Damage[2] or Damage[1], Damage[4], Damage[6], Damage[7]) or (Hit and Hit.Name == "Head" and Damage[3]) and Damage[1] * Damage[2] or Damage[1]
	end
	--GORE
	if TargetHumanoid.Health - TrueDamage <= 0 and not TargetHumanoid.Parent:FindFirstChild("gibbed") then
		if Hit then
			if Hit.Name == "Head" or Hit.Name == "Torso" or Hit.Name == "Left Arm" or Hit.Name == "Right Arm" or Hit.Name == "Right Leg" or Hit.Name == "Left Leg" or Hit.Name == "UpperTorso" or Hit.Name == "LowerTorso" or Hit.Name == "LeftUpperArm" or Hit.Name == "LeftLowerArm" or Hit.Name == "LeftHand" or Hit.Name == "RightUpperArm" or Hit.Name == "RightLowerArm" or Hit.Name == "RightHand" or Hit.Name == "RightUpperLeg" or Hit.Name == "RightLowerLeg" or Hit.Name == "RightFoot" or Hit.Name == "LeftUpperLeg" or Hit.Name == "LeftLowerLeg" or Hit.Name == "LeftFoot" then
				VisualizeGore:FireAllClients(Hit, TargetHumanoid.Parent, GoreData)
			end
		end
	end
	if Tagger then
		local TargetTEAM = TargetHumanoid.Parent:FindFirstChild("TEAM")
		local TEAM = Tool.Parent:FindFirstChild("TEAM")
		local CanDamage = (TEAM and TargetTEAM) and (TargetTEAM.Value ~= TEAM.Value) or DamageModule.CanDamage(TargetHumanoid.Parent, Tagger)
		if ExplosiveData and ExplosiveData[1] and ExplosiveData[5] then
			if TargetHumanoid.Parent.Name == Tagger.Name then
				CanDamage = (TargetHumanoid.Parent.Name == Tagger.Name)
				if ExplosiveData[7] then
					TrueDamage = TargetHumanoid:GetState() ~= Enum.HumanoidStateType.Freefall and TrueDamage or (TrueDamage * (1 - ExplosiveData[6]))
				else
					TrueDamage = TrueDamage * (1 - ExplosiveData[6])
				end
			end
		end
		if TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso and CanDamage then
			while TargetHumanoid:FindFirstChild("creator") do
				TargetHumanoid.creator:Destroy()
			end
			local creator = Instance.new("ObjectValue",TargetHumanoid)
			creator.Name = "creator"
			creator.Value = Tagger
			Debris:AddItem(creator, 5)
			if Critical[1] then
				local CriticalChanceRandom = Random.new():NextInteger(0, 100)
				if CriticalChanceRandom <= Critical[2] then
					TargetHumanoid:TakeDamage(math.abs(TrueDamage * Critical[3]))
				else
					TargetHumanoid:TakeDamage(math.abs(TrueDamage))
				end			
			else
				TargetHumanoid:TakeDamage(math.abs(TrueDamage))
			end
			if Misc[1] > 0 then --knockback
				if not (ExplosiveData and ExplosiveData[1] and ExplosiveData[5]) then
					local Shover = Tagger.Character.HumanoidRootPart or Tagger.Character.Head
					local Duration = 0.1
					local Speed = Misc[1] / Duration
					local Velocity = (TargetTorso.Position - Shover.Position).Unit * Speed
					local ShoveForce = Instance.new("BodyVelocity")
					ShoveForce.MaxForce = Vector3.new(1e9, 1e9, 1e9)
					ShoveForce.Velocity = Velocity
					ShoveForce.Parent = TargetTorso
					Debris:AddItem(ShoveForce, Duration)					
				end
			end
			if Misc[2] > 0 and Tagger.Character.Humanoid and Tagger.Character.Humanoid.Health ~= 0 then --lifesteal
				if ExplosiveData and ExplosiveData[1] and ExplosiveData[5] then
					if not TargetHumanoid.Parent.Name == Tagger.Name then
						Tagger.Character.Humanoid.Health = Tagger.Character.Humanoid.Health + (TrueDamage * Misc[2])
					end
				else
					Tagger.Character.Humanoid.Health = Tagger.Character.Humanoid.Health + (TrueDamage * Misc[2])
				end
			end
			if Misc[3] then	--affliction
				local roll = math.random(1, 100)
				if roll <= Misc[5] then
					if not TargetHumanoid.Parent:FindFirstChild(Misc[4]) then
						local Debuff = Tool:FindFirstChild("GunScript_Server"):FindFirstChild(Misc[4]):Clone()
						Debuff.creator.Value = creator.Value
						Debuff.Parent = TargetHumanoid.Parent
						Debuff.Disabled = false
					end
				end
			end		
		end
	else
		warn("Unable to register damage because player is no longer existing here")
	end
end

Players.PlayerAdded:Connect(function(player)
	for i, v in pairs(_G.TempBannedPlayers) do
		if v == player.Name then
			player:Kick("You cannot rejoin a server where you were kicked from.")
			warn(player.Name.." tried to rejoin a server where he/she was kicked from.")
			break
		end
	end
end)
