Unanchoring parts with explosions

I have been working on a new game lately, and I am working with explosions. My goal is to make explosions that explode near buildings to tear them apart by unanchoring them. Here is my code:

Exp.Hit:Connect(function(TheObject, Distance)
    	pcall(function()
    		    if not TheObject.Parent:FindFirstChild("Humanoid") then
    	            TheObject.Anchored = false
    	      end
       end)
end)

The problem I am facing right now is that it doesn’t unanchor all the parts that it hits for some reasson. It manages to break the windows of my house, and other small details, but the roof and the walls stands there like nothing has happened. I have checked their values, and they don’t get unanchored.

giphy

Thanks in advance

7 Likes

Couldn’t you just destroy the welds instead of unanchoring the parts?

1 Like

What @vwize said.

TheObject.Anchored = false
TheObject:BreakJoints()
2 Likes

Problem

I didn’t build with welds. I will try to rebuild and add welds and see how it works out :+1:

I just tried to remake the buildings with welds, and it didn’t work

1 Like

did you make the house hollow?

2 Likes

Considering you’re muting the entire content of the function for whatever reason and throwing away the values it returns on top of that, yeah I can see why you may be encountering issues especially with regards to a part not getting unanchored.

Consider actually using what pcall returns if you’re going to use it so that you’re capable of debugging your code when it goes wrong or implement proper conditionals into your statement such as checking if the item hit was a BasePart.

explosion.Hit:Connect(function (part, distance)
    if (part:IsA("BasePart") and not (part.Parent:FindFirstChildOfClass("Humanoid")) then
        part.Anchored = false
    end
end)

There could be other factors related to the way you’ve constructed the house that are affecting the explosion’s ability to function properly.

2 Likes

The house is constructed in a way that it should be able to be destroyed, however, it would seem like only small parts get unanchored (See the gif).

I have pcall to make sure that the script doesn’t stop all of a sudden. Also, I did have an if statement before that checked if it was a basepart, but that didn’t help either.

Here is the full script that I used

script.Parent.Touched:Connect(function(Object)
	local Exp = Instance.new("Explosion")
	Exp.Parent = script.Parent.Parent
	Exp.Position = script.Parent.Position - Vector3.new(0,2,0)
	Exp.BlastRadius = 5	
		Exp.Hit:Connect(function(TheObject, Distance)
			pcall(function()
			if not TheObject.Parent:FindFirstChild("Humanoid") then
				TheObject.Anchored = false
				print(TheObject)
				print(TheObject.Anchored)
			end
			end)
		end)
		wait(0.01)
		script.Parent:Destroy()
end)

The script is supposed to be inside a projectile that will explode as soon as it hits it’s target.

1 Like

I just realized that if I make the blast radius ~20 then it works.

The problem is that when I do that, it becomes too big (Meaning that players far away from the explosion could still get hit).

I have a similar problem, the meshparts get unanchored and I have given breakjoints() too.
The blast radius is set to 1000 and blast pressure is set to 10000 but the parts dont get thrown of after being unanchorred.

i want them to fly on hit by explosion

1 Like

An explosion only launches parts once, so my advice is to make 1 explosion that is visible to unanchor the parts

Then do another explosion that is invisible to make the parts fly.

This is just an idea, its probs not the best way to go about it but it should work.

2 Likes

My advice is to weld all part to a primarypart through a script and then unachor all parts and anchor the primary part, they will stay together and when an explosion comes, they will fall apart (the ones hit)

Agreed:
Use the QPerfectionweld script, which welds all parts of a model and then unanchores them, i believe. Then let the Explosion do all the work. It breaks welds.
Why would you not want a Player caught in the Explosion to be damaged?

Don’t use PCalls. You want to know what errors you are getting, track them down, and solve them for every possible case.

Better yet: Mod the Rocket Launcher script, which does exactly what you want; works; and was made by Roblox.

Or: Here’s a Shotgun script, which uses a very small explosion, to blast the limbs off Players, instead of outright killing them; just to mess with them…

EDIT: Old. No longer works, probably because Filter Enabled
Uber-Shotgun - Roblox

1 Like

Or instead of using QPerfectionweld you can do one by urself too, just name a part that covers the whole house “Primary” or smth like that, make its transparency 1 and cancollide off and also anchor it. After that just insert a script like this:

for i,v in pairs(script.Parent:GetChildren()) do
      if v:IsA("BasePart") then
            local w = Instance.new("WeldConstraint", v)
            w.Part0 = v
            w.Part1 = script.Parent:WaitForChild("Primary")
            v.Anchored = false --If they weren't unanchored, it unanchores them
      end
end
1 Like