how do i make a part explode once it touches any object (player or part ect.) ive looked around but ill ive found was for on contact with players. anyone know how to do this?
how do i make a part explode?
2 answers
you can use Part.Touched to detect part touch. And then clone the explosion effect to explosion part position
Now, you want to use a few functions here to get you going. The Touched function will be useful for detecting when the player touches the part. We also want to make sure that the explosion occurs ONLY when the player touches the part, not any other parts. To do this, we use FindFirstChild. Again, we will use FindFirstChild to make sure there is not already an explosion. It would be inefficient to have loads of explosions just because the broken parts of the character keep making contact with the block. Here is the script. Please read the comments for more explanation.
local PressureofBlast = 100 -- This is how strong the explosion will be. MUST BE A NUMBER!
local RadiusofBlast = 100 --This is the size of the explosion, it will not change visually.
local ExplosionType = Enum.ExplosionType.NoCraters
--Change the line above to "local ExplosionType = Enum.ExplosionType.Craters" if you want terrain to dissapear upon explosion.
script.Parent.Touched:Connect(function(hit) --Touched Function
if script.Parent:FindFirstChild("Explosion") then --Makes sure unnecessary explosions don't occur
warn("There is already an explosion inside the part.") --Feel free to remove these two statements
print("Explosion wasn't created.")
else
if hit.Parent:FindFirstChild("Humanoid") then --Makes sure the explosion only occurs if player touches.
local explosion = Instance.new("Explosion", script.Parent) --Creates new explosion
explosion.ExplosionType = ExplosionType --Destroys terrain
explosion.BlastPressure = tonumber(PressureofBlast)
explosion.BlastRadius = tonumber(RadiusofBlast)
end
end
end)
If you're looking for just parts, we don't need the FindFirstChild statement for the Humanoid.
local PressureofBlast = 100 -- This is how strong the explosion will be. MUST BE A NUMBER!
local RadiusofBlast = 100 --This is the size of the explosion, it will not change visually.
local ExplosionType = Enum.ExplosionType.NoCraters
--Change the line above to "local ExplosionType = Enum.ExplosionType.Craters" if you want terrain to dissapear upon explosion.
script.Parent.Touched:Connect(function(hit) --Touched Function
if script.Parent:FindFirstChild("Explosion") then --Makes sure unnecessary explosions don't occur
warn("There is already an explosion inside the part.") --Feel free to remove these two statements
print("Explosion wasn't created.")
else
local explosion = Instance.new("Explosion", script.Parent) --Creates new explosion
explosion.ExplosionType = ExplosionType --Destroys terrain
explosion.BlastPressure = tonumber(PressureofBlast)
explosion.BlastRadius = tonumber(RadiusofBlast)
end
end)
Now, the script wasn't tested for parts, only for humanoids, so if this doesn't work, please post a comment.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
i dont know how to do that
i cant code it for you
ok i understand