local function e(Q)if Q and Q~=Workspace then local L=Q:FindFirstChild("\072\117\109\097\110\111\105\100")if L then return Q,L else return e(Q.Parent)end end return nil end local function Q(Q,L)if Rocket and Q then if IGNORE_LIST[string.lower(Q.Name)]or Q.Parent==Tank then return end local Z=CreatorTag.Value if Z then if Z.Character and Z.Character:IsAncestorOf(Q)then return end if not Z.Neutral then local L=e(Q.Parent)local C=PlayersService:GetPlayerFromCharacter(L)if C and(C~=Z and C.TeamColor==Rocket.BrickColor)then return end end end Rocket.Transparency=1 Rocket.CFrame=CFrame.new(L.X,L.Y,L.Z)local C,d=e(Q.Parent)if d and d.Health>0 then DamageTag(C,DIRECT_HIT_DAMAGE)end ypcall(function()for e=1,1,1 do ExplodeClone=Explode:clone()ExplodeClone.Position=Rocket.Position ExplodeClone.Mesh.Scale=Vector3.new(5,5,5)*1 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)CreatorTag.Parent=script Rocket:Destroy()end end
-- Returns the ancestor that contains a Humanoid, if it exists
local function FindCharacterAncestor(subject)
	if subject and subject ~= Workspace then
		local humanoid = subject:FindFirstChild("Humanoid")
		if humanoid then
			return subject, humanoid
		else
			return FindCharacterAncestor(subject.Parent)
		end
	end
	return nil
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)] or (otherPart.Parent == Tank) 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]]
		local character, humanoid = FindCharacterAncestor(otherPart.Parent)
		if humanoid and humanoid.Health > 0 then -- Humanoids are tagged and damaged
			DamageTag(character, DIRECT_HIT_DAMAGE)
		end

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

		ypcall(function()
			for i = 1, 1 do
				ExplodeClone = Explode:clone()
				ExplodeClone.Position = Rocket.Position
				ExplodeClone.Mesh.Scale = Vector3.new(5, 5, 5) * 1
				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
