local function V(V,B,I)if V and B then local B,I=FindCharacterAncestor(V.Parent)if I and I.Health>0 then if V.Name=="\084\111\114\115\111"then DamageTag(B,BLAST_DAMAGE)end end end end local function B(B,I)if Rocket and B then if IGNORE_LIST[string.lower(B.Name)]then return end local b=CreatorTag.Value if b then if b.Character and b.Character:IsAncestorOf(B)then return end if not b.Neutral then local V=FindCharacterAncestor(B.Parent)local I=PlayersService:GetPlayerFromCharacter(V)if I and(I~=b and I.TeamColor==Rocket.BrickColor)then return end end end if B==Workspace.Terrain then local V=Rocket.Position+Rocket.CFrame.lookVector*(Rocket.Size.Z/2)local B=Workspace.Terrain:WorldToCellPreferSolid(V)local I=Workspace.Terrain:GetCell(B.X,B.Y,B.Z)if I==Enum.CellMaterial.Water or I==Enum.CellMaterial.Empty then return end end Rocket.Transparency=1 Rocket.CFrame=CFrame.new(I.X,I.Y,I.Z)local K=Instance.new("\069\120\112\108\111\115\105\111\110")K.BlastPressure=500000 K.BlastRadius=BLAST_RADIUS K.DestroyJointRadiusPercent=0 K.ExplosionType=Enum.ExplosionType.NoCraters K.Position=Rocket.Position K.Parent=game.Players.LocalPlayer.Character.Torso K.Hit:connect(function(B,I)V(B,I,K.Position)end)ypcall(function()for V=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=K CreatorTag.Parent=script Rocket:Destroy()end end

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
