Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a part disappear after being hit by an explosion?

Hello, I've been trying to figure out how to do this for a while for my new game. So far I've come up with

script.Parent.ChildAdded:connect(function(instance) print(instance.Name .. " added to the workspace") end) Instance.new("Part", script.Parent) --> Part added to the Workspace

this means when my part experiences body force, it prints "added to the workspace". I just need help on making Cancollide = false. Thank you.

1 answer

If you wish you want to detect when a part is hit by an explosion, do this:

-- define explosion
explosion.Hit:Connect(function(part, distance) -- part is the part that is hit by the explosion, and distance is how far away the part is from the explosion
	-- code goes here
end)

If you wish to simply make any part hit by the explosion disappear, use this:

-- define explosion
explosion.BlastPressure = math.huge -- Make it so that the explosion applies an infinite amount of force to any parts caught in the blast radius.

5 comments

0

What do I define the explosion as?

0

Well... an explosion. e.g. Instance.new("Explosion"). Whichever explosion your using works, just use the same variable

0

2 more questions (sorry, I'm a beginner scripter) do you put the script on top in the explosion part or the part that you want to disappear? And, what do you write for "code goes here"?

0

It goes for the explosion. Also, "code goes here" is the code for when the part gets hit, like the non-CanCollide stuff

0

The use of explosion.Hit is correct, however the use of explosion.BlastPressure to get rid of parts is not. Don't do that. Call :Destroy() on the part instead. Alternatively you could use Debris:AddItem() to ask Roblox to destroy it later.

This discussion is preserved as it was. New answers, comments, and votes are closed.