Script is saying that 16 does not equal 16

Hello, I am having a problem.

I have these two values that both equal 16 but when I put “value1 == value2” it returns false??


I printed both of the values to make sure that they were both equal to 16, and then on the next line I am checking to see whether they are equal or not. This was the output:

wdawadwadwdawadawd
For some reason, even though the two values are 16 it still returns false?? Can somebody please help thank you.

Are they the same type of values? I think Lua is one of the languages that will return false if the values aren’t of the same type

You cannot use = inside a print I learned from I do not know

It could be possible that both of the variables could be referenced as different Value Types, are you sure that you’re equaling them to the same “Number” value? And not a string?

image

You may have to use “tonumber(value)” if the value is showing as a string.

It is most likely what has been discussed in the replies above; it is using two different types of values.

Try this for example:

print(tostring(16)==16)

It will print false since they are two different types.

Just use tonumber() if you want it to be a number you can add or subtract or tostring() if you need it to be shown on UI.

You can use == which compares if two things are equal. You can’t use just = because that tries to set a value and that doesn’t work when you call functions and things.

@OP What is the ClassName of the Space value? Is it a StringValue? If so, the value will be a string, and you have to convert its Value to a number when you compare. You can do that with tonumber:

tonumber(player:WaitForChild("Space").Value)

Also, just a quick little tip so you don’t need to type as much, you can give multiple things to the print function and it will add a space between each:

print(num, tonumber(player:WaitForChild("Space").Value)) -- Would print "16 16"

This also can do some special things, for example, with the new output it can show you tables (and you can’t do that if you make the table a string)

dwaawawwaddawdaawdawd

Thank you bro it worked :pray:

3 Likes

Is one a string and the other a int value?