I'm trying to make a vehicle damage system. But I ran into a problem, I don't know how to figure out what one is the one that is 20 or above.
script.Parent.Touched:Connect(function(hit)
local hp = script.Parent.MainHealth local impactVelocity = parent.Velocity.Magnitude local hitVelocity = hit.Velocity.Magnitude if impactVelocity >= 20 or hitVelocity >= 20 then hp.Value = hp.Value - --What one is >= 20 end
end)
Hello! I am here to help. The most efficient way (at least that I know of) is to make an if statement INSIDE the if statement, Example:
local var1 = 1 local var2 = 15 local var3 = 25 if var2 >= 20 or var3 >= 20 then if var2 >= 20 then print('var2 is greater than 20!') else print('var3 is greater than 20!') end end
It checks if either are greater than 20. If either are, then it checks which one is greater than 20.
So, your "fixed" code:
local hp = script.Parent.MainHealth local impactVelocity = parent.Velocity.Magnitude local hitVelocity = hit.Velocity.Magnitude if impactVelocity >= 20 or hitVelocity >= 20 then if impactVelocity >= 20 then hp.Value = hp.Value - impactVelocity else hp.Value = hp.Value - hitVelocity end end
. Hope this helped you!
Note: I mean, there really isn't an explanation to this, it's just that you make another if statement inside the if statement.