local v={}local function P(P,i,n)if P and i then local i,l=FindCharacterAncestor(P.Parent)if i then local v=CreatorTag.Value if v and not v.Neutral then local P=PlayersService:GetPlayerFromCharacter(i)if P and(P~=v and P.TeamColor==Rocket.BrickColor)then return end end end if l and l.Health>0 then if not IsInTable(v,l)then print("\084\097\103\103\101\100")table.insert(v,l)ApplyTags(l)l:TakeDamage(BLAST_DAMAGE)end else if P.Name~="\072\097\110\100\108\101"then P:BreakJoints()local v=Instance.new("\066\111\100\121\070\111\114\099\101",P)v.Force=((P.Position-n).unit*BLAST_FORCE)*P:GetMass()DebrisService:AddItem(v,.1)end end end end local i=false local function n(v)for v,n in ipairs(v)do if Rocket then if IGNORE_LIST[string.lower(n.Name)]then return end local v=CreatorTag.Value if v then if v.Character and v.Character:IsAncestorOf(n)then return end if not v.Neutral then local P=FindCharacterAncestor(n.Parent)local i=PlayersService:GetPlayerFromCharacter(P)if i and(i~=v and i.TeamColor==Rocket.BrickColor)then return end end end if n==workspace.Terrain then local v=Rocket.Position+Rocket.CFrame.lookVector*(Rocket.Size.Z/2)local P=workspace.Terrain:WorldToCellPreferSolid(v)local i=workspace.Terrain:GetCell(P.X,P.Y,P.Z)if i==Enum.CellMaterial.Water or i==Enum.CellMaterial.Empty then return end end i=true local l=Instance.new("\069\120\112\108\111\115\105\111\110")l.BlastPressure=0 l.BlastRadius=BLAST_RADIUS l.ExplosionType=Enum.ExplosionType.NoCraters l.Position=Rocket.Position l.Parent=workspace l.Hit:Connect(function(v,i)P(v,i,l.Position)end)script.Parent=l CreatorTag.Parent=script Rocket:Destroy()end end end

local TaggedHumanoids = {}
local function OnExplosionHit(hitPart, hitDistance, blastCenter)
	if hitPart and hitDistance then
		local character, humanoid = FindCharacterAncestor(hitPart.Parent)

		if character then
			local myPlayer = CreatorTag.Value
			if myPlayer and not myPlayer.Neutral then -- Ignore friendlies caught in the blast
				local player = PlayersService:GetPlayerFromCharacter(character)
				if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
					return
				end
			end
		end

		if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
			if not IsInTable(TaggedHumanoids,humanoid) then
				print("Tagged")
				table.insert(TaggedHumanoids,humanoid)
				ApplyTags(humanoid)
				humanoid:TakeDamage(BLAST_DAMAGE)
			end
		else -- Loose parts and dead parts are blasted
			if hitPart.Name ~= 'Handle' then
				hitPart:BreakJoints()
				local blastForce = Instance.new('BodyForce', hitPart) --NOTE: We will multiply by mass so bigger parts get blasted more
				blastForce.Force = (hitPart.Position - blastCenter).unit * BLAST_FORCE * hitPart:GetMass()
				DebrisService:AddItem(blastForce, 0.1)
			end
		end
	end
end
local Isexplosion = false
local function OnTouched(otherParts)
	for i,otherPart in ipairs(otherParts)do
		if Rocket then
			-- Fly through anything in the ignore list
			if IGNORE_LIST[string.lower(otherPart.Name)] then
				return
			end

			local myPlayer = CreatorTag.Value
			if myPlayer then
				-- Fly through the creator
				if myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
					return
				end

				-- Fly through friendlies
				if not myPlayer.Neutral then
					local character = FindCharacterAncestor(otherPart.Parent)
					local player = PlayersService:GetPlayerFromCharacter(character)
					if player and player ~= myPlayer and player.TeamColor == Rocket.BrickColor then
						return
					end
				end
			end

			-- Fly through terrain water
			if otherPart == workspace.Terrain then
				--NOTE: If the rocket is large, then the simplifications made here will cause it to fly through terrain in some cases
				local frontOfRocket = Rocket.Position + (Rocket.CFrame.lookVector * (Rocket.Size.Z / 2))
				local cellLocation = workspace.Terrain:WorldToCellPreferSolid(frontOfRocket)
				local cellMaterial = workspace.Terrain:GetCell(cellLocation.X, cellLocation.Y, cellLocation.Z)
				if cellMaterial == Enum.CellMaterial.Water or cellMaterial == Enum.CellMaterial.Empty then
					return
				end
			end
			Isexplosion = true
			-- Create the explosion
			local explosion = Instance.new('Explosion')
			explosion.BlastPressure = 0 -- Completely safe explosion
			explosion.BlastRadius = BLAST_RADIUS
			explosion.ExplosionType = Enum.ExplosionType.NoCraters
			explosion.Position = Rocket.Position
			explosion.Parent = workspace

			-- Connect custom logic for the explosion
			explosion.Hit:Connect(function(hitPart, hitDistance) OnExplosionHit(hitPart, hitDistance, explosion.Position) end)
			-- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
			script.Parent = explosion
			CreatorTag.Parent = script
			Rocket:Destroy()
		end
	end
end
