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)
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)