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.
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.
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.
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.
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…
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