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
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