I have a model named Car. I am attempting to check if any part in Car is touched, and if so, run a function that damages the car, etc. However, I cannot get this to work. I believe I could use GetChildren and check if each one is a part, but would this be laggy? Using the Touched event directly on Car did not work:
car.Touched:connect(collide)
Apparently I cannot use the Touched event on a model. This is understandable.
So, how would I do this without causing lag, having glitchy hitboxes, or some similar problem?
Also, how do I check if the part I collided with is part of the model?
I understand that you don't want the script to be laggy and looping through the parts will not cause lag. Initially it is just doing a normal index key pairs loop and all you have to do is check if the part is a part and if it is then just connect the touched event. In no way is this inefficient or bad.
for _, Part in pairs(Model:GetChildren()) do if Part:IsA('Part') then Part.Touched:connect(function() print(Part.Name .. ' was touched.') end) end end