Let's say we have an IntValue in the PlayerGui, it's value is 1.
I would normally check it with this..
if game.Players.IntellectualBeing.IntValue.Value = 1 then print('The number is 1!') end
Is there a more efficient way?
And what if I want the script to check if the script is multiple numbers and do a different outcome for different numbers. I do not want it to just print out the number, if I did I would just do
print(game.Players.IntellectualBeing.IntValue.Value)
I want it to do different outcomes for each number, I am just using print() as an example.
Examples
print('The number is 1!') --Occurs when IntValue is 1
game.Workspace:ClearAllChildren() --Occurs when IntValue is 2
local a = Instance.New("Part") --Occurs when IntValue is 3
and etc...
Well, first off, when checking values in an if statement, we use two equal signs, like this: "==" (One equal sign sets a variable's value). You are definitely heading in the right direction with the if statements, though. When you want to check for different values, however, you would use "elseif", which checks for a different condition if the previous are not met. It would look like this:
value = game.Players.IntellectualBeing.IntValue.Value if value == 1 then print("The number is 1!") elseif value == 2 then game.Workspace:ClearAllChildren() elseif value == 3 then local a = Instance.new("Part") end
And what if I want the script to check if the script is multiple numbers and do a different outcome for different numbers.
Personally, I would do this
function case(n) (({ ['1']=function()print("one")end; ['2']=function()print("TWO")end; ['3']=function()print("III")end; ['17']=function()print("zero")end; ['100']=function()print("???")end; })[tostring(n)]or function()end)() end case(game.Players.IntellectualBeing.IntValue.Value)
but maybe I just like to have a little too much fun.