Attempt to compare string "<=" error

Hello!

A strange error has been happening in my script. Every time I use a specific sign to compare strings my script just breaks down, but when I use anything else it’s fine but it’s not what I want.

Here is the script:


	if plr.leaderstats[currency].Value >= price then
		print(plr.Name.. " is hatching "..eggName)
		plr.leaderstats[currency].Value -= price
		plr.leaderstats.Eggs.Value += 1
		
		return true
	else 
		return false
	end
	
end


Error ^

I have tried changing the sign to “==” for example and it works but it is not at all what I want to do to achieve what I want. I am really stuck on this, someone told me it was an error with the returns but that makes no sense at all since it works when I use a different sign.

If you know anything please let me know, thank you!

1 Like

You can’t do maths with strings. Make sure the value is not a stringvalue it must be a NumberValue or a IntValue.

1 Like

Send the full script and I can help you out.

There is nothing to help out its clearly a simple fix by doing what I said.

Sure but maybe he is a bit confused on what part to change.

Then he will need to ask but sending the code will help with nothing at all.

If I see the code then I can see what to change to fix it, then I would send the correct script then tell him what he did wrong.

Wrong, the datastore instance needs to be changed and its not in that script.

How about a value where I can put in a word or letters as a value, I cant do that with NumberValue’s or IntValue’s.

image

Is that a cost of the egg to get what currency you need to buy it?

Strings can’t contain be compared to numbers. do the tonumber() function or make it a IntValue.

I keep being ignored, send the full script and information or just be like that.

There is a cost and a currency name so the script knows what to deduct the cost of.

image

image
Show me where local currency is if its that property u said try doing currency.Value

Try changing plr.leaderstats.Eggs.Value += 1 to plr.leaderstats.Eggs.Value + 1 || This might be your problem, although I’m not too sure. Possibly just try it to see if I’m right, as it doesn’t hurt! (:

2 Likes

try this

if plr.leaderstats[currency.Value].Value >= price.Value then
		print(plr.Name.. " is hatching "..eggName)
		plr.leaderstats[currency.Value].Value -= price.Value
		plr.leaderstats.Eggs.Value += 1
		
		return true
	else 
		return false
	end
	
end

Small correction. As long as the string value is a number you can still do math with it and a number value. You just cannot compare them using >, <, >=, <= operators.

For example

local str = "1"
local n = 2

local x = str + n -- this = 3

I ment with words not numbers in string value…

Edited, if you have

local currency = location.Value
local price = location.Value

then remove .Value off it and copy and paste what I done.

Its honestly my mistake for not catching this before, All I had to do was change

plr.leaderstats.Eggs.Value += 1

to

plr.leaderstats.Eggs.Value = plr.leaderstats.Eggs.Value + 1

Thanks, I learned something new!