I don't see anything wrong with your proposed script (assuming you uncomment out the commented part of the 'if'), though I always recommend making sure that "hit.Parent" isn't nil before trying to access a property of hit.Parent. I also question your use of the wait command, since your cannon ball might hit multiple parts in quick succession, and each will trigger a new "instance" of the OnTouched function (so you'll have multiple instances of your function running simultaneously, and all will wait for 0.8 seconds)
Anyway, a bug is usually the result of a mismatch between what you believe to be true and what is actually true. To solve this, use "print" statements to figure out what is going on. ex:
function onTouched(hit)
print("Hit, mass, anchored:", hit, hit:GetMass(), hit.Anchored)
if hit:GetMass() < 70 and not hit.Anchored then
script.Parent.CanCollide = false
print("Humanoid in parent:", hit.Parent:FindFirstChild("Humanoid"))
if hit.Parent:FindFirstChild("Humanoid") then hit.Humanoid.Health = 0 end
wait(0.8)
print("After wait caused by touching", hit)
end
end
The print statements should help you understand why your script is behaving the way it is and allow you to make corrections. (Of course, you should always delete the print statements once it's working, or else it'll unnecessarily clutter your Output and slow down your game -- the print() command takes time).
1 comment
I would think it would be something like, if hit:Get(something to identify hit humanoid entity?) then humanoid.Health = 0 so that the hit humanoid dies.