So, before adding the if-then statement cash.value >= amountvalue it was working just fine but players could send infinite money and go debt (in -value). I made this so players wouldn’t go negative. yes it can have letters but it wouldn’t send. If i inserted numbers then it would work.
Okay then text can either be
→ 482000
And can be also
→ texttexttext
Can we se a “simulation” (video) of the process to see what exactly happens?
You can have the simulation in direct if you friend me since my game is friends only. I don’t have a video recorder.
This is the error from ingame (not the studio):
Have you tried to use tonumber()?
Try this:
amountvalue = tonumber(amount)
From what I can see in your code, you have this:
local amount = script.Parent.Parent.Amount.Text
local amountvalue = script.Parent.Amount.Value
amountvalue = amount
The amount pulls the text, amountvalue pulls the actual value. Then the amountvalue (amountvalue = amount) pulls the text and assigns it into the value. However, from what I know, Lua does convert strings into numbers if it recognizes it being a numerical object.
Nope. I just don’t understand why it doesn’t work? I have a store in my game and it compares the cash.Value with the price of the item and everything works fine.
Same error, nothing changed… (character limit)
By looking at the code, everything looks fine as it should. So the main problem is how the script handles the number put in the textbox and the way it returns it to the script.
Perhaps try replacing the line at the start with this:
local amount = tonumber(script.Parent.Parent.Amount.Text)
However, if that doesn’t resolve it, my best advice would be that, if the field for putting the amount of coins is a TextBox, that you make a function outside of those lines of code so it recognizes when a player hits enter (TextBox | Roblox Creator Documentation) manually.
Then, have the function check if the text inside of the box is specifically a number or it has something in its way. If it succeeds, make that result the amoutvalue; if not, make it so it errors so they can’t proceed further unless it’s a number.
pretty sure it’s supposed to say
elseif cash.Value <= amountvalue then
you forgot the “=”
ummm… 1st. the problem is on line 16… and 2nd. if the money is equal to amount then why wouldn’t they be able to pay?
Doesnt work. (character limit)
on the line of getting the receiver?
if cash.Value >= amountvalue then
is the cash value an intvalue or a numbervalue?
I might just have found the problem, but I don’t know how to solve it in code. When I do:
amountvalue = amount
it might still think that amountvalue is a textbox!
numbervalue obviously. it works everywhere else as I said in the posts above.
right so for your reply above you’re setting the amount value value to “amount”
in your case i would try to print the value of cash before firing the “if” to check if it exists in the first place
i’ve encountered this issue before with the same type of system, my side developer ended up finding it after a while by adding a bunch of sanity checks and finding the root
No;
local amount = script.Parent.Parent.Amount.Text
local amountvalue = script.Parent.Amount.Value
Amountvalue is something which holds the value.
Amount is referred to as a text object.
Yes it works perfectly. It says the amountvalue. (I put 100 to pay and it said 100 so its fine)