Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

5 comments

0

could you elaborate?

0

why not use 2 separate if statements lmao

0

greatneil80 Because i only want one dealing damage at a time

0

exclusive or should help then

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.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.