I have an explosion meant to destroy welds and unanchor parts. It does both of those things, but it doesn’t also fling them. Another explosion is required to fling them.
I’m pretty sure I know why it’s happening. I think it’s because the event is firing after the explosion has already tried to fling the parts around it. But I’m just not sure how to fix it.
Part of the script handling the explosion:
NewPrompt.Triggered:Once(function()
local Explosion = Instance.new("Explosion")
local HitEvent = Explosion.Hit:Connect(function(hit)
if hit:HasTag("Placeable") then
hit.Anchored = false
if hit:FindFirstChildWhichIsA("WeldConstraint") then
hit:FindFirstChildWhichIsA("WeldConstraint"):Destroy()
end
end
end)
Explosion.Parent = workspace
Explosion.Position = block.Position
Explosion.DestroyJointRadiusPercent = 0
Explosion.BlastRadius = 5
task.delay(1, function()
HitEvent:Disconnect()
end)
block:Destroy()
end)
I don’t think you have to destroy WeldConstraints with an Explosion (see the link for the explanation), it does it automatically depending on the BlastRadius.
Try parenting the Explosion to the Workspace after you set all the other Properties, instead of doing it first.
The property that controls destroying WeldConstraints is a different one called “DestroyJoinRadiusPercent”. I had set this to 0 in my script. Leaving it at 1 actually solves the problem, destroying the welds and sending them flying.
However, I had this set to 0 in the script because if a player gets caught in the explosion when it’s set to 1, they take damage. I don’t want that. Any way you know of to stop damage?
Thanks for the help so far!
@ActuallyAToaster This is likely because, by the time the shockwaves that happen whenever a part explodes hit the parts, the script isn’t fast enough nor is the physics update to no longer apply the WeldConstraint. What you should do instead of using WeldConstraints as it’s bad practice is use the actual Weld instance.
Also what you could do is have their be an invisible explosion that applies just so you can figure out what parts need to be unanchored then apply another explosion.
Depends mostly on what you are trying to achieve, if you want to ever animate the parts such as tweeting their positions it can be better to use the Weld rather than WeldConstraints since the Weld will also break if either part is moved allowing for a breakable hinge type idea but up to whatever is the goal for how useful they are.