function Explode()if not Crashed.Value then Crashed.Value=true Plane:BreakJoints()local m=Instance.new("\069\120\112\108\111\115\105\111\110")m.Parent=game.Workspace m.Position=Engine.Position m.BlastRadius=(Plane:GetModelSize()).magnitude/2 m.BlastPressure=200000.0 if Engine:findFirstChild("\084\104\114\117\115\116")then Engine.Thrust:Destroy()end if Engine:findFirstChild("\068\105\114\101\099\116\105\111\110")then Engine.Direction:Destroy()end delay(5,function()Plane:Destroy()end)end end function GetPlaneParts(m)for m,S in pairs(m:GetChildren())do if S:IsA("\066\097\115\101\080\097\114\116")then table.insert(Parts,S)end GetPlaneParts(S)end end function onAutoCrash()if AutoCrash.Value then Explode()end end function DetectExplosions(m)if m.ClassName=="\069\120\112\108\111\115\105\111\110"then if m.BlastPressure>0 then local S=(m.Position-Engine.Position).magnitude if S<=m.BlastRadius+2 then if not Crashed.Value then Explode()end end end end end function IsObstacle(m)if not m:IsDescendantOf(Plane)and m.CanCollide then local S=m:FindFirstChild("\080\108\097\110\101\084\097\103")if S and S.Value~=Plane or not S then return true end end return false end function IsDescendantOfPlayer(m)for S,P in pairs(game.Players:GetPlayers())do if P and P.Character then if m:IsDescendantOf(P.Character)then return P end end end return nil end GetPlaneParts(Plane)for m,S in pairs(Parts)do S.Touched:connect(function(m)if not Ejected.Value then if CanCrash.Value and not Crashed.Value then if IsObstacle(m)then local P=game.Players:GetPlayerFromCharacter(script.Parent.Parent)if P then local S=IsDescendantOfPlayer(m)if S==P then return end end if S.Velocity.magnitude>=Force.Value then Explode()end end end elseif Ejected.Value then if not Crashed.Value then if IsObstacle(m)then if m.Parent.Name~="\069\106\101\099\116\111\114\083\101\097\116"then if not IsDescendantOfPlayer(m)then Explode()end end end end end end)end game.Workspace.DescendantAdded:connect(DetectExplosions)AutoCrash.Changed:connect(onAutoCrash)
--------------------------------------------------------------------------
function Explode() --This function makes the plane explode
	if not Crashed.Value then
		Crashed.Value = true
		Plane:BreakJoints()
		local Explosion = Instance.new("Explosion")
		Explosion.Parent = game.Workspace
		Explosion.Position = Engine.Position
		Explosion.BlastRadius = Plane:GetModelSize().magnitude / 2 --This makes the BlastRadius the size of the plane
		Explosion.BlastPressure = 2e5
		if Engine:findFirstChild("Thrust") then
			Engine.Thrust:Destroy()
		end
		if Engine:findFirstChild("Direction") then
			Engine.Direction:Destroy()
		end
		delay(5, function()
			Plane:Destroy()
		end) --This removes the plane after 5 seconds
	end
end

function GetPlaneParts(Model) --This function gets all the parts on the plane
	for _, v in pairs(Model:GetChildren()) do
		if v:IsA("BasePart") then
			table.insert(Parts, v) --This inserts all the parts into the "Parts" table
		end
		GetPlaneParts(v)
	end
end

function onAutoCrash() --This function is activated when the AutoCrash value becomes true
	if AutoCrash.Value then
		Explode()
	end
end

function DetectExplosions(Object) --This is a function that I created which detects explosions in the workspace
	if Object.ClassName == "Explosion" then --If the object detected was an explosion...
		if Object.BlastPressure > 0 then
			local Dist = (Object.Position - Engine.Position).magnitude
			if Dist <= (Object.BlastRadius + 2) then
				if not Crashed.Value then
					Explode()
				end
			end
		end
	end
end

function IsObstacle(Obj) --This function determines whether Obj is an obstacle that can be used to destroy the plane
	if (not Obj:IsDescendantOf(Plane)) and Obj.CanCollide then
		local PlaneTag = Obj:FindFirstChild("PlaneTag")
		if (PlaneTag and PlaneTag.Value ~= Plane) or not PlaneTag then
			return true
		end
	end
	return false
end

function IsDescendantOfPlayer(Obj)
	for _, v in pairs(game.Players:GetPlayers()) do
		if v and v.Character then
			if Obj:IsDescendantOf(v.Character) then
				return v
			end
		end
	end
	return nil
end

GetPlaneParts(Plane) --This activates the "GetPlaneParts" function
for _, v in pairs(Parts) do --This gets all the parts in the "Parts" table
	v.Touched:connect(function(Object) --This is activated if any of the bricks are touched
		if not Ejected.Value then
			if CanCrash.Value and not Crashed.Value then
				if IsObstacle(Object) then
					local Player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
					if Player then
						local HitPlayer = IsDescendantOfPlayer(Object)
						if HitPlayer == Player then
							return
						end
					end
					if v.Velocity.magnitude >= Force.Value then
						Explode()
					end
				end
			end
		elseif Ejected.Value then
			if not Crashed.Value then
				if IsObstacle(Object) then
					if Object.Parent.Name ~= "EjectorSeat" then
						if not IsDescendantOfPlayer(Object) then
							Explode()
						end
					end
				end
			end
		end
	end)
end

game.Workspace.DescendantAdded:connect(DetectExplosions) --The detect explosions is a DescendantAdded function
AutoCrash.Changed:connect(onAutoCrash) --Pretty self explanatory. When the AutoCrash value is changed, the "onAutoCrash" function is activated
