-
What do you want to achieve?
I want to check if the NumberValue is the same as the script value
-
What is the issue?
If I use too many if else, the performance will drop and it will take time if the value I want to check for is at the bottom.
-
What solutions have you tried so far?
I haven’t tried any solutions, as I don’t know what to use.
This is what I mean:
local Value = script.Parent.NumberValue.Value
if Value == 0 then
else if Value == 1 then
else if Value == 2 then
else if Value == 3 then
else if Value == 4 then
else if Value == 5 then
end
end
end
end
end
end
1 Like
Firstly, it’s elseif
, not else if
, which is why it’s causing those many end
s
Secondly, if you just want to do something specific when something is a certain value, you can maybe use a dictionary with functions?
local Value = script.Parent.NumberValue.Value
local valuefuns = {
[1] = function()
print("The value is one")
end,
[2] = function()
print("The value is two")
end
}
valuefuns[Value]() --If the value is 2, it will print The value is two
I’m not sure exactly what you mean by
I can’t assign the dictionary to the NumberValue.
And yes, SelectedSlot is a NumberValue.
I forgot to add the ()
when firing a dictionary function, at SelectedSlot[Value]
, put ()
at the end
SelectedSlot[Value]()
1 Like