How to make an if statement check if the value of a variable is something

so basically how would i make an if statement check if a variables value is a certain value?

So if it was this script

local Food = Food
--Checks if foods value is food(where the if function goes)

I want to do this because i’m going to replicate the script and change a certain value so i want the script to go along with it since it will know what to do when it encounters it.

3 Likes
local Food = "Food"

if Food == "Food" then
  -- runs conde here
end
1 Like

Just literally do this?

if variable == (whatever you want) then

end
1 Like

Here are basic example:

local myVar = "Test"
if myVar == "Test" then
--do stuff
else
--do stuff
end
local myVar = 6
if typeof(myVar) == "number" then
print("its a number!")
end
local cash = Player.leaderstats.Cash

if cash.Value >= 100 then
--do something
end
local Food = {"Watermelon","Banana","Burger"}
local Variable = "Coffee"

if table.find(Food,Variable) then
print("It's  food!")
else
print("Not food!")
end

There is a way to shorten an if statement:

local myVal = false
local food = myVal == true and "is food" or "Not Food"
print(food)

(You can use _G.Var for global variables to use in multiple scripts).

local Number = 10

if Number % 2 ==  0 then
print("even!")
else
print("odd!")
end
3 Likes
local bool = true
local myString = bool == true and "Is True" or "Not True"
print(myString)

The variable myString will be Is True if the variable bool is equal to true, otherwise it will return Not True

1 Like