Let's say we have an IntValue in the PlayerGui, it's value is 1.
I would normally check it with this..
1 | if game.Players.IntellectualBeing.IntValue.Value = 1 then |
2 | print ( 'The number is 1!' ) |
3 | 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:
1 | value = game.Players.IntellectualBeing.IntValue.Value |
2 | if value = = 1 then |
3 | print ( "The number is 1!" ) |
4 | elseif value = = 2 then |
5 | game.Workspace:ClearAllChildren() |
6 | elseif value = = 3 then |
7 | local a = Instance.new( "Part" ) |
8 | 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
01 | function case(n) |
02 | (( { [ '1' ] = function () print ( "one" ) end ; |
03 | [ '2' ] = function () print ( "TWO" ) end ; |
04 | [ '3' ] = function () print ( "III" ) end ; |
05 | [ '17' ] = function () print ( "zero" ) end ; |
06 | [ '100' ] = function () print ( "???" ) end ; |
07 | } ) [ tostring (n) ] or function () end )() |
08 | end |
09 |
10 | case(game.Players.IntellectualBeing.IntValue.Value) |
but maybe I just like to have a little too much fun.