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

How do I get the name of a brick that's hit another brick?

So I have a gun that fires a bullet, the bullets are called "Bullet" when I fire a bullet at the trigger brick I wan't it to print I got shot, and else to do nothing if it didn't get shot by a part called bullet. Here's what I have but It won't work! Much appreciated if you could help me! :)

a = script.Parent
function onBrickShot(hit)
	if hit.Parent.Name == "Bullet" then
		print("I am a brick that has just been shot!")
		else
	end
end
script.Parent.Touched:connect(onBrickShot)

1 comment

0

It may not work if bullet is anchored.

1 answer

✓ Accepted answer

hit is equal to the Part that fired the event. If that part is a bullet, then hit will equal that bullet. Therefore you need to check if hit.Name equals "Bullet". hit.Parent.Name will just give you the name of its Parent, which is most likely Workspace.

 --You never use the variable defined on this line
function onBrickShot(hit)
	if hit.Name == "Bullet" then
		print("I am a brick that has just been shot!")
		--No need for the else
	end
end

script.Parent.Touched:connect(onBrickShot)

1 comment

0

Thanks Perci! I really appreciate it!

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