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

Explain to me the "Hit" event?

Using an explosion as the event to trigger some code. Put it in a rough example showing the event listener please.

2 answers

✓ Accepted answer
local x=Instance.new("Explosion")
x.Hit:connect(function(hit)
	hit.BrickColor=BrickColor.new("Really blue")
end)
x.Parent=workspace

Any part partially inside the BlastRadius will turn blue.

1 comment

0

Now it makes sense to me. I know how I'm going to do this...

As any event, we use :connect() to connect a function to run when this event happens. This function is passed the arguments which are provided with the event.

According to the wiki, the Explosion.Hit event passes an Instance as first argument and a Number as second argument. The first argument is the part which is hit, the second is the distance from the explosion center to that part.

Example code: remove all red bricks when an explosion fires.

function FireExplosion(position)
	local new = Instance.new("Explosion")
	new.Hit:connect(function(part, distance)
		if part and part.BrickColor == BrickColor.Red() then
			part:Destroy()
		end
	end)
	new.Position = position or Vector3.new()
	new.Parent = game.Workspace
end

FireExplosion()

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