I forgot how to do it. I need my script to not act if the parent of the hit object is nil, because otherwise it returns an error.
Here's my script.
function onTouched(hit)
if hit.Parent.Name == "Monorail" then
local explosion = Instance.new("Explosion")
explosion.Parent = hit
explosion.Position = hit.Position
wait(0.5)
hit:remove()
wait(5)
hit.Parent:remove()
end
end
script.Parent.Touched:connect(onTouched)

2 comments
For bullets,
hit.Parentcan benil, so it is good for your health to check forhit.Parentbefore using it in an onTouched script.Also, USE A LOCAL VARIABLE! Or else this script won't be very useful!