local x={}local function N(N,M,f)if N and M then local M,R=FindCharacterAncestor(N.Parent)if M then local x=CreatorTag.Value if x and not x.Neutral then local N=PlayersService:GetPlayerFromCharacter(M)if N and(N~=x and N.TeamColor==Rocket.BrickColor)then return end end end if R and R.Health>0 then if not IsInTable(x,R)then print("\084\097\103\103\101\100")table.insert(x,R)ApplyTags(R)R:TakeDamage(BLAST_DAMAGE)end else if N.Name~="\072\097\110\100\108\101"then local x=script.Effects.Effect:Clone()local M=script.Effects.Smoke:Clone()local R=script.Effects.Smoke2:Clone()local p=Instance.new("\070\105\114\101")p.Heat=10000 p.Size=100 if IGNITE_PARTS==true then p.Parent=N end if SPECIAL_EFFECTS==true then x.Enabled=true R.Enabled=true M.Enabled=true x.Parent=N R.Parent=N M.Parent=N end if UNANCHOR_PARTS==true then N.Anchored=false end if BREAK_JOINTS==true then N:BreakJoints()end local h=Instance.new("\066\111\100\121\070\111\114\099\101",N)h.Force=((N.Position-f).unit*BLAST_FORCE)*N:GetMass()DebrisService:AddItem(h,.1)wait(.1)x.Enabled=false R.Enabled=false wait(2)x:Destroy()R:Destroy()M.Enabled=false end end end end local function M(x)if Rocket and x then if IGNORE_LIST[string.lower(x.Name)]then return end local M=CreatorTag.Value if M then if M.Character and M.Character:IsAncestorOf(x)then return end if not M.Neutral then local N=FindCharacterAncestor(x.Parent)local f=PlayersService:GetPlayerFromCharacter(N)if f and(f~=M and f.TeamColor==Rocket.BrickColor)then return end end end if x==workspace.Terrain then local x=Rocket.Position+Rocket.CFrame.lookVector*(Rocket.Size.Z/2)local N=workspace.Terrain:WorldToCellPreferSolid(x)local M=workspace.Terrain:GetCell(N.X,N.Y,N.Z)if M==Enum.CellMaterial.Water or M==Enum.CellMaterial.Empty then return end end local f=Instance.new("\069\120\112\108\111\115\105\111\110")f.BlastPressure=0 f.BlastRadius=BLAST_RADIUS f.ExplosionType=Enum.ExplosionType.NoCraters f.Position=Rocket.Position f.Parent=workspace f.Hit:Connect(function(x,M)N(x,M,f.Position)end)script.Parent=f CreatorTag.Parent=script Rocket:Destroy()end end
-- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
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
				local effect = script.Effects.Effect:Clone()
				local smoke = script.Effects.Smoke:Clone()
				local smoke2 = script.Effects.Smoke2:Clone()
				local fire = Instance.new("Fire")
				fire.Heat = 10000
				fire.Size = 100

				if IGNITE_PARTS == true then
					fire.Parent = hitPart
				end

				if SPECIAL_EFFECTS == true then
					effect.Enabled = true
					smoke2.Enabled = true
					smoke.Enabled = true
					effect.Parent = hitPart
					smoke2.Parent = hitPart
					smoke.Parent = hitPart
				end

				if UNANCHOR_PARTS == true then
					hitPart.Anchored = false
				end

				if BREAK_JOINTS == true then
					hitPart:BreakJoints()
				end

				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)
				wait(0.1)
				effect.Enabled = false
				smoke2.Enabled = false
				wait(2)
				effect:Destroy()
				smoke2:Destroy()
				smoke.Enabled = false
			end
		end
	end
end

local function OnTouched(otherPart)
	if Rocket and otherPart 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

		-- 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
