Hello! I am trying to make a server-wide money system that shows up via a GUI.
Is there a way to make it so if the number on said GUI is greater than a certain number, something happens? (Such as buying something)
If not, is there a way to do something similar without using a leader stat, because this is a server-wide GUI not something that differs depending on the user.
Note: I know this is a little off-topic, I didn’t know where to put it.
You’ll need to convert the text into a number using the ‘tonumber()’ global and then you’ll need to use one of the various comparison/relational operators to compare it with something, i.e;
local TextBox = script.Parent --Text box that contains some text.
local Number = tonumber(TextBox.Text) --Convert the textbox's text into a number.
--Compare the number with something here.
local TextLabel = script.Parent
local NumberConvert = tonumber(TextLabel.Text)
local requiredNumber = 100
if NumberConvert => requiredNumber then
print(string.format("Player has enough cash available! (%s)", NumberConvert))
end
I don’t think => is a valid syntax for binary operation, though I might be wrong as I only had a quick look at the grammar of Luau (Grammar - Luau), and the binop doesn’t seem to include ‘=>’ but it does include ‘>=’.
Attempting "Hello world!" > 0" will result in an error. Therefore tonumber()'s use is definitely necessary.
The textbox’s text should be wrapped inside a call to ‘tonumber()’ which will return either a number (if the value could be converted) or nil (if the value couldn’t be converted).
If you can make the assumption that the text is a number (because you’re the one setting it), then a tonumber call is completely unnecessary. If you cannot make that assumption, then the call can be necessary.
In the example snippet I provided I used a ‘TextBox’ instance, I was under the assumption that whatever value is being compared has been user provided, hence tonumber()'s use is essentially required (you could opt to use pcall()/xpcall() instead but both are of lesser performance).