Why I got this this error? Attempt to perform arithmetic(add) on nil and number, that really help me

Bruh, You can’t campare string value with another string value.
You must turn them into a number value!

The type only tells you the value’s class, such as string, object, number and more. They DO NOT tell how large the number is!

Look
image

image

twenty

I mean make it impossible to donate up to possible

It is still a string. If you’d print it’s type it would say it’s a string.

then what I need to do to put it Number?

Just use tonumber(value). It will convert this string into a number

1 Like

Turn if script.Parent.TextBox.Text >= script.Parent.Parent.Frame.Cash then into if tonumber(script.Parent.TextBox.Text) >= tonumber(script.Parent.Parent.Frame.Cash) then

1 Like

In the esleif you’re comparing two strings but you can’t do that

image


that still not Working

image

Do you know that the code script.Parent.TextBox.Text is a string! This is like comparing "This sentence" is bigger than 1 !

then what I need to do I tried all

The error is because Cash is an instance, likely a textlabel or textbox as well, so you’d need to convert the text of it as well

Also the way you’re doing the if statements seems a bit confusing. You show really only have to use an if-else statement and an guard clause before it in the event the converted text be nil

local inputCash = tonumber(script.Parent.TextBox.Text)
local currentCash = tonumber(script.Parent.Parent.Frame.Cash.Text)
if not inputCash or not currentCash then
    warn("Something went wrong trying to convert text to number")
end

if inputCash > currentCash then
    print("Not enough cash")
else
    player.leaderstats.Cash.Value += inputCash
end

I realised now I’m a bit too late with my post but I think the issue of improper if statement usage still applies from the looks of it

Another edit: okay from your current code you immediately get the text properties, so in your current code the text will always return an empty string/ whatever is the default value, you get the text properties when you click on the gui button, so put those variables in the MouseButton1Click event

I tried it but that not working

image

Same thing I mentioned, you update the variables when they need to be updated in your case you put them outside of the OnServerEvent, the issue with this is that they will be set when the script runs, and will always reference the result of the converted text that was there at the time the script reached that line, you need to update them in the event, not outside of it

Look what I did

image

Read what I said carefully, inputCash and currentCash need to be made inside of the OnServerEvent, you create them outside of it and thus will never update when they need to update

That still not working I tried it
image
image
image

Why are you checking textboxes on the server exactly? The textbox’s text property would only change for the client, you’d need to make the client give the server the text of the TextBox to use,

Similar to what you did here

But you only need to give in the text of the TextBox, again, make sure you do not do the same mistake that I have mentioned already