More Efficient Destruction Script?

Hello.
Some of you have seen my game war on the sea.
I am making a better explosion script
It just seems too excessive and I feel like it could be a LOT smaller.
Thanks.

repeat
	wait()
until script.Parent.Health.Value <= 0 
script.Parent.PatrolAi:Destroy()
script.Parent.Enabler:Destroy()
script.Parent.qPerfectionWeld:Destroy()
script.Parent.Escort:Destroy()
script.Parent.Name = "PileOfDestroyedJunk"
script.Parent.Parent = workspace
script.Parent:BreakJoints()
local explosion = Instance.new("Explosion")
explosion.DestroyJointRadiusPercent = 0 
explosion.BlastPressure = 5000000
explosion.Position = script.Parent.BluePlane.Position
explosion.Parent = workspace
local TeamManager = require(game:GetService("ServerScriptService").MainGameScript.GameManager.TeamManager)
TeamManager:AddTeamScore(game:GetService("Teams").Red.TeamColor, 1)
for v,Part in pairs(script.Parent:GetDescendants())  do
	if Part:IsA("BasePart") then
		local fire = Instance.new("Fire")
		fire.Parent = Part
		fire.Size = 15
	end
end
for i,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("BasePart") then
		v.Touched:connect(function(part)
			if part.Name == "Terrain" or (part:FindFirstAncestor("RedShips")) then
				local health = part.Parent:FindFirstChild("Health")
				health.Value = health.Value - math.random(1,15)
				local explosion = Instance.new("Explosion")
				explosion.Position = v.Position
				explosion.BlastRadius = 0
				explosion.Parent = workspace
				v:Destroy()
			end
		end)
	end
end
for i,v in pairs(script.Parent.Engine:GetChildren()) do
	if not v:IsA("Weld") then
		v:Destroy()
	end
end
wait(15)
script.Parent:Destroy()

Alright from what I understand its a boat war game.

for i,v in pairs(script.Parent:GetDescendants()) do
if v:IsA(“BasePart”) then
v.Touched:connect(function(part)

for that instead of making a connection to every part in the boat make a single or more hitbox welded to the boat that is invisible and cancollide off then use that as the hitbox to release the load on the server

repeat
wait()
until script.Parent.Health.Value <= 0

use GetPropertyChangedSignal
ex.

script.Parent.Health:GetPropertyChangedSignal("Value"):Connect(function()
if script.Parent.Health.Value < 1 then
--Run every other bit of code here
end
end)

for v,Part in pairs(script.Parent:GetDescendants()) do
if Part:IsA(“BasePart”) then
local fire = Instance.new(“Fire”)
fire.Parent = Part
fire.Size = 15
end
end

Do this in the client to release load from the server. To do that just fire a remote event to all clients using FireAllClients() with the argument of the model you want on fire then just put that code on the client response

1 Like

@ortacise Thanks!
This is to make a plane explode. :joy:

1 Like