How to find all parts that were hit by an explosion?

Hello.
I am trying to make a script which detects if one of the parts that were hit by an explosion that the player made is named “GoldenPart”.
But when I try using “Explosion.hit”, the only part I get was the first part that the explosion hit, instead of all the parts.
How is it possible getting all parts in an array or something close, and find which of them are named as “GoldenPart”?

You can use Region3 and FindPartInRegion3. So yuo would create a region3 where the explosion is hit and get all the touching parts with FindPartInRegion3.

Thanks for the help, But FindPartInRegion3 can’t be exactly the same as the explosive itself… I need the script to check the parts that were inside that explosion…

Yes, so you would calculate how big the explosion is, and then create a relative region3 to go with it

1 Like

According to the wiki, Explosion.Hit fires per part (thus returning a single part for every part hit, not an array).

For example:

local explosion = Instance.new("Explosion")
explosion.BlastRadius = 20
explosion.Position = script.Parent.OriginPart.Position

explosion.Hit:Connect(function(part, distance)
	if part.Name == "GoldenPart" then
		print("explosion hit a golden part ("..distance.." studs away).")
		part.Color = Color3.new(0, 1, 0)
	end
end)
	
explosion.Parent = game.Workspace

Make sure the explosion’s BlastRadius is large enough, it’s 4 by default (which would be too small to detect further parts).

22 Likes

Thanks for the code! i like it

1 Like