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

How to Check if a Value is Between to Numbers?

Asked by
H26O 44
5 years ago

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
0
Please accept my answer if works! Miniller 562 — 5y

1 answer

Log in to vote
1
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

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
<, <=, >, >=, ~=, == are relational operators not arithmetic operators. Arithmetic operators are ^, *, /, +, -  and I don't know if modulus is considered one of those but % is modulus User#24403 69 — 5y
Ad

Answer this question