I cant compare instances to a number?

so for some reason i keep getting an error when im trying to compare numbers added to eachother, to see if they are bigger than a given range, but it keeps saying its an instance

Screenshot 2024-09-20 114227

and yes i know it doesnt have to be in parentheses, but even when i tried it without them, it did the exact same thing, is this a bug, or am i just confused on something

3 Likes

print it before doing the if statment and see if its a number or an instance

range is an instance make sure that ur passing the correct argument

Convert the values to number

tonumber(value.z)
tonumber(value.x)

you cannot convert instances to numbers that only work with strings

if you check the script, it is not an instance, it is a value of a Vector3 which is a number

1 Like

then the error msg was going to be smt like this
{62774305-A0D6-4227-8690-E9232887629C}

1 Like

He is getting Z axis and X axis of them, not the exact whole vector3.

1 Like

yes but if he got the X or Z value then they should be numbers
the error msg says that he is comparing an instance to a number so calling tonumber() on an instance would do nothing

If it says it is an instance, then he should convert it to number.

converting an instance to a number with tonumber() will return nil and will give an error because you cant compare a number with nil

Please read Vector3 | Documentation - Roblox Creator Hub first.

1 Like

i readed it already before
i still don’t get why to use tonumber() on an instance/vector3 can you show an example?

the error that he is getting is because range is an instance calling tonumber() on it would return nil which will result in an error

range is a number as you see in the script and Z and X are numbers of Vector3 too, i do not know how do you think they are instances.

if the script is thinking it is a instance then he got to convert that number to an actual number using tonumber()


that error means that range is an instance and (Xvel + Zvel) are numbers already

range IS an instance according to the error. He probably accidentally passed an instance instead of a number into the function. @GE_0E is right.

I’m trying to fix the issue by the function I am seeing right now, you might be right, but my point is not wrong too.

calling tonumber() on a vector3 would still do nothing

print(tonumber(Vector3.new(5,5,5)))

{1EE0EEB0-40F6-4E98-BD06-85F60E54E05F}

I’m not lying this is happening 100% because the OP passed an instance instead of a number. There is nothing wrong with the function.

Man, he is using the Z and X components not the whole Vector3…

1 Like

That’s mean that this post is missing something.