Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i figure out what value is equal to or above 20?

Asked by 3 years ago
Edited 3 years ago

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)

0
could you elaborate? Wayyllon 170 — 3y
0
why not use 2 separate if statements lmao greatneil80 2647 — 3y
0
greatneil80 Because i only want one dealing damage at a time Surblaab 2 — 3y
0
exclusive or should help then joshthegamer456 93 — 3y
0
Wayyllon I'm trying to make the vehicle take damage when it hits a part and gets hit by a part, impactVelocity is for how fast the car hits something and hitVelocity is how fast the car is hit by something, and hp is the health of the vehicle so when the vehicle hits something or is hit by something fast enough it will take damage but I can't figure out how to find what one is 20 or above. Surblaab 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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.

Ad

Answer this question