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

How to Check if a Value is Between to Numbers?

I understand how to use if statements and such however I am having trouble trying to compare something such as a player's Vector3 value to see if their Y axis is Greater then 50 but less then 100, how could I measure this?

How could I modify the also statement below to say less then 50 but greater then 100?

if game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position.Y > 100 then
	print("Test")
end

1 comment

0

Please accept my answer if works!

1 answer

✓ Accepted answer

If this is your code, and you want to fix this, you can detect if a number is between two other numbers like this:

local value = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position.Y
if value > 50 and value < 100 then -- Value is bigger than 50, and less than 100
	print("Test")
end

Explanation: In programming languages, there are relational operators. Two examples for that are > and < . This two are used between two numbers, or two other values arithmetic can be done on. Let's say we got this statement: x > y this means: x is bigger than y. < it's reverse, x < y x less than y. We need (for this script) another operator: and. if statement1 and statement2 then the code in that IF statement will run if statement1 and statement2 are both true. Example: if 5 == 5 and 6 == 6 then code in the IF stat. will run. Example2: if 5 == 5 and 6 == 7 then code in the IF stat. will NOT run

1 comment

1

<, <=, >, >=, ~=, == are relational operators not arithmetic operators. Arithmetic operators are ^, *, /, +, -  and I don't know if modulus is considered one of those but % is modulus

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