Help with a nuke that destroys everything!

Hey there developers,

So I made a nuke recently that should destroy everything, but here’s the problem; it doesn’t destroy everything.

What it’s ment to do is expand out and destroy everything that is inside of it. But it doesn’t. It expands, but doesn’t destroy stuff.

Here is the script I currently have:

while true do
	c = game.Workspace:GetChildren()
	for i =1,#c do
		if ((c[i].className == "Part" or c[i].className == "TrussPart" or c[i].className == "WedgePart" or c[i].className == "Seat" or c[i].className == "VehicleSeat") and (c[i].Position - script.Parent.Position).magnitude < (script.Parent.Size.X / 2.1) - 5) then
		if c[i].Locked == false then
		c[i].Material = Enum.Material.CorrodedMetal
		c[i].Anchored = false
		c[i]:BreakJoints()

		local miniboom = script.Parent.Parent.Parent.SmallBoom:Clone()

		miniboom.Parent=c[i]
		miniboom:Play()
		game.Debris:AddItem(miniboom,1)
	end
end
		
if (c[i].className == "Model") then
	
end

g = c[i]:GetChildren()
for j =1,#g do
	if ((g[j].className == "Part" or g[j].className == "TrussPart" or g[j].className == "WedgePart" or g[j].className == "Seat" or g[j].className == "VehicleSeat") and g[j].Name ~= script.Parent.Name and g[j].Name ~= "Glow" and (g[j].Position - script.Parent.Position).magnitude < (script.Parent.Size.X / 2.1) - 5) then
	g[j].Material = Enum.Material.CorrodedMetal
	g[j].Anchored = false
	g[j]:BreakJoints()
	
	local miniboom = script.Parent.Parent.Parent.SmallBoom:Clone()
	miniboom.Parent=c[i]
	miniboom:Play()
	game.Debris:AddItem(miniboom,1)
end
	
if (g[j].className == "Model") then
	
end

t = g[j]:GetChildren()
for s =1,#t do
	if ((t[s].className == "Part" or t[s].className == "TrussPart" or t[s].className == "WedgePart" or t[s].className == "Seat" or t[s].className == "VehicleSeat") and t[s].Name ~= script.Parent.Name and t[s].Name ~= "Glow" and (t[s].Position - script.Parent.Position).magnitude < (script.Parent.Size.X / 2.1) - 5) then
	t[s].Material = Enum.Material.CorrodedMetal
	t[s].Anchored = false
	t[s]:BreakJoints()	
end

if (t[s].className == "Model") then
		
end
	
a = t[s]:GetChildren()
for z =1,#a do
	if ((a[z].className == "Part" or a[z].className == "TrussPart" or a[z].className == "WedgePart" or a[z].className == "Seat" or a[z].className == "VehicleSeat") and a[z].Name ~= script.Parent.Name and a[z].Name ~= "Glow" and (a[z].Position - script.Parent.Position).magnitude < (script.Parent.Size.X / 2.1) - 5) then
	a[z].Material = Enum.Material.CorrodedMetal
	a[z].Anchored = false
	a[z]:BreakJoints()
end
	
if (a[z].className == "Model") then
	
end

p = a[z]:GetChildren()
for l =1,#p do
	if ((p[l].className == "Part" or p[l].className == "TrussPart" or p[l].className == "WedgePart" or p[l].className == "Seat" or p[l].className == "VehicleSeat") and p[l].Name ~= script.Parent.Name and p[l].Name ~= "Glow" and (p[l].Position - script.Parent.Position).magnitude < (script.Parent.Size.X / 2.1) - 5) then
	p[l].Material = Enum.Material.CorrodedMetal
	p[l].Anchored = false
	p[l]:BreakJoints()
end
end
end
end
end
end
wait(.3)
end

:heart: Thank you if you help!

1 Like

“classname” should be writen like “ClassName”. Also i recommend just using the c[i]:IsA("BasePart"), because that gets every part type. It will also reduce the if statement. I hope it works.

1 Like

Thank you! I will try it out right now.

Also where would this go in the code? Do you mean c[i].className == "BasePart"?

1 Like

I would recommend using Spatial Query to get all parts inside and destroy them:

for _,part in workspace:GetPartsInPart(nuke) do
	part:Destroy()
end

“nuke” would of course be the part that’s expanding and being used for said part detection.

1 Like

Where would I put this in the code also? Would I do this:

for _,part in workspace:GetPartsInPart(tip) do -- but where would this go?
	part.Material = Enum.Material.CorrodedMetal
	part.Anchored = false
	part:BreakJoints()
end

That would probably be where it goes. I would recommend trying things out before posting though :+1:

1 Like

This is the code I have right now:

while true do
	for _,part in workspace:GetPartsInPart(tip) do
		part.Material = Enum.Material.CorrodedMetal
		part.Anchored = false
		part:BreakJoints()
	end
end

image

???

Should be the nuke part that is gonna destroy all the parts and that increases in size. Use part:Destroy() instead of :BreakJoints()

1 Like

I don’t want to because I want it to be unanchored. Would I just remove :BreakJoints()?

I read it wrong. You can keep it

1 Like

You need to make sure your “tip” variable is properly defined. You’ll likely want to define it near the top of the script, above this part.

1 Like

Instead of using this, just use Workspace:GetDescendants(), it will get everything in workspace.

1 Like

uhh first…
please fix your code format, for the love of god respectfully, dont use i pair

while true do
    local objects = game.Workspace:GetDescendants()
    local object = next(objects)

    while object do
        if object:IsA("BasePart") or object:IsA("TrussPart") or object:IsA("WedgePart") or object:IsA("Seat") or object:IsA("VehicleSeat") then
            local distance = (object.Position - script.Parent.Position).magnitude
            if distance < (script.Parent.Size.X / 2.1) - 5 and not object.Locked then
                object.Material = Enum.Material.CorrodedMetal
                object.Anchored = false
                object:BreakJoints()

                local miniboom = script.Parent.Parent.Parent.SmallBoom:Clone()
                miniboom.Parent = object
                miniboom:Play()
                game.Debris:AddItem(miniboom, 1)
            end
        end
        object = next(objects, object)
    end

    wait(0.3)
end

1 Like

It still doesn’t work, is there any reason why? BY THE WAY EVERYONE, THE CODE IS IN WORKSPACE IN A PART CALLED “TIP”, SO IF THAT HELPS THEN YEAH.

Can anyone help? I’ve been waiting for a response… (sorry if that sounded a bit rude)

In a script, inside of the Tip.

    
  
local Range = 1000
  for i,child in ipairs( game.Workspace:GetDescendants()) do
        if object:IsA("BasePart") or object:IsA("TrussPart") or object:IsA("WedgePart") or object:IsA("Seat") or object:IsA("VehicleSeat") then
            local distance = (object.Position - script.Parent.Position).magnitude
            if distance <= Range and not object.Locked then
                object.Material = Enum.Material.CorrodedMetal
                object.Anchored = false
                object:BreakJoints()

                local miniboom = script.Parent.Parent.Parent.SmallBoom:Clone()
                miniboom.Parent = object
                miniboom:Play()
                game.Debris:AddItem(miniboom, 1)
            end
        end
      
    end
1 Like