Here is the script:
script.Parent.Touched:connect(function(Part) if Part.Parent ~= "SmallShip" or "Cannon" or "Barrel" then if Part.Name == "CannonBall" or "Explosion" then script.Parent.Health.Value = script.Parent.Health.Value - 1 print('Ship took damage!') end end if script.Parent.Health <= 0 then script.Parent.Parent.Weld:Remove() print('Ship destroyed!') end end)
For some reason it is printing the ship took damage when anything touches it, how do I fix this?
Correct me if I'm wrong but I believe when you're using " or " at the if statement you should specify it as you did before, Example:
if Part.Parent ~= "SmallShip" or Part.Parent ~= "Cannon" or Part.Parent ~="Barrel" then
And It seems that you might want to use and instead of or since if your Part.Parent is "Cannon" and you don't want it to continue It'll still continue since It always checks if Part.Parent isn't "SmallShip" and the same thing to if your Part.Parent is "SmallShip" Since if Part.Parent is also not "Cannon" it'll continue. So basically in the end It'll always continue.
So you would just need to change the first and second loop, would be like this:
if Part.Parent ~= "SmallShip" and Part.Parent ~= "Cannon" and Part.Parent ~= "Barrel" then if Part.Name == "CannonBall" or Part.Name == "Explosion" then
Hopefully that helps you with that issue. :)