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

How to check if IntValue is a certain number?

Asked by 10 years ago

Let's say we have an IntValue in the PlayerGui, it's value is 1.

I would normally check it with this..

1if game.Players.IntellectualBeing.IntValue.Value = 1 then
2    print('The number is 1!')
3end

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

2 answers

Log in to vote
3
Answered by 10 years ago

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:

1value = game.Players.IntellectualBeing.IntValue.Value
2if value == 1 then
3    print("The number is 1!")
4elseif value == 2 then
5    game.Workspace:ClearAllChildren()
6elseif value == 3 then
7    local a = Instance.new("Part")
8end
Ad
Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

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

01function 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)()
08end
09 
10case(game.Players.IntellectualBeing.IntValue.Value)

but maybe I just like to have a little too much fun.

Answer this question