local function S(S,k,F)if S and k then local k,F=FindCharacterAncestor(S.Parent)if F and F.Health>0 then if S.Name=="\084\111\114\115\111"then DamageTag(k,BLAST_DAMAGE)end end end end local function k(k,F)if Rocket and k then if IGNORE_LIST[string.lower(k.Name)]then return end local w=CreatorTag.Value if w then if w.Character and w.Character:IsAncestorOf(k)then return end if not w.Neutral then local S=FindCharacterAncestor(k.Parent)local F=PlayersService:GetPlayerFromCharacter(S)if F and(F~=w and F.TeamColor==Rocket.BrickColor)then return end end end if k==Workspace.Terrain then local S=Rocket.Position+Rocket.CFrame.lookVector*(Rocket.Size.Z/2)local k=Workspace.Terrain:WorldToCellPreferSolid(S)local F=Workspace.Terrain:GetCell(k.X,k.Y,k.Z)if F==Enum.CellMaterial.Water or F==Enum.CellMaterial.Empty then return end end Rocket.Transparency=1 Rocket.CFrame=CFrame.new(F.X,F.Y,F.Z)local W=Instance.new("\069\120\112\108\111\115\105\111\110")W.BlastPressure=500000 W.BlastRadius=BLAST_RADIUS W.DestroyJointRadiusPercent=0 W.ExplosionType=Enum.ExplosionType.NoCraters W.Position=Rocket.Position W.Parent=game.Players.LocalPlayer.Character.Torso W.Hit:connect(function(k,F)S(k,F,W.Position)end)ypcall(function()for S=1,3,1 do ExplodeClone=Explode:clone()ExplodeClone.Position=Rocket.Position ExplodeClone.Mesh.Scale=Vector3.new(5,5,5)*5 ExplodeClone.CFrame=ExplodeClone.CFrame*CFrame.fromEulerAnglesXYZ(math.random(-10000,10000)/100,math.random(-10000,10000)/100,math.random(-10000,10000)/100)ExplodeClone.Parent=game.Players.LocalPlayer.Character.Torso NewScript=Rocket.Script:clone()NewScript.Disabled=false NewScript.Parent=ExplodeClone end end)script.Parent=W CreatorTag.Parent=script Rocket:Destroy()end end
-- Customized explosive effect that doesn't affect teammates and only breaks joints on dead parts
local function OnExplosionHit(hitPart, hitDistance, blastCenter)
	if hitPart and hitDistance then
		local character, humanoid = FindCharacterAncestor(hitPart.Parent)
		if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
			if hitPart.Name == "Torso" then
				--ApplyTags(humanoid)
				DamageTag(character, BLAST_DAMAGE)
				--humanoid:TakeDamage(BLAST_DAMAGE)
			end
		end
	end
end

local function OnTouched(otherPart, RayPos)
	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

		Rocket.Transparency = 1
		Rocket.CFrame = CFrame.new(RayPos.X, RayPos.Y, RayPos.Z)

		-- Create the explosion
		local explosion = Instance.new("Explosion")
		explosion.BlastPressure = 500000 -- Completely safe explosion
		explosion.BlastRadius = BLAST_RADIUS
		explosion.DestroyJointRadiusPercent = 0
		explosion.ExplosionType = Enum.ExplosionType.NoCraters
		explosion.Position = Rocket.Position
		explosion.Parent = game.Players.LocalPlayer.Character.Torso

		-- Connect custom logic for the explosion
		explosion.Hit:connect(function(hitPart, hitDistance)
			OnExplosionHit(hitPart, hitDistance, explosion.Position)
		end)

		ypcall(function()
			for i = 1, 3 do
				ExplodeClone = Explode:clone()
				ExplodeClone.Position = Rocket.Position
				ExplodeClone.Mesh.Scale = Vector3.new(5, 5, 5) * 5
				ExplodeClone.CFrame = ExplodeClone.CFrame
					* CFrame.fromEulerAnglesXYZ(
						math.random(-10000, 10000) / 100,
						math.random(-10000, 10000) / 100,
						math.random(-10000, 10000) / 100
					)
				ExplodeClone.Parent = game.Players.LocalPlayer.Character.Torso
				NewScript = Rocket.Script:clone()
				NewScript.Disabled = false
				NewScript.Parent = ExplodeClone
			end
		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
