Attempt to compare nil and number [ERROR]

Hi! I’m trying to check if the players cash value is higher than the value in a table.

Here’s my script:

image

But i get this error all the time:

ServerScriptService.Main:103: attempt to compare nil and number

line 103 is if plr.leaderstats.Cash.Value >= price then

Thank you!

1 Like

The error is telling you that one side of the comparison is a number, while the other is nil. Which one is which? Well, you could just figure that out with a print…

print(plr.leaderstats.Cash.Value, " >= ", price)

But, to save you the trouble, it’s price (because the left side would error out since you’re directly indexing the hierarchy/properties).

So, iteminfo doesn’t have a price key.

1 Like

Thanks! I figured out that price == nil, but i can’t figure out how to fix this. Here’s my local script that’s firing the event:
image

Maybe try:

game.ReplicatedStorage.Events.Buy:FireServer({name, price, false})

@Darkmist101 is right. This is very easily exploitable. On the server, I would make a table with all of the item’s and their prices. Then when they go to buy something double check that what the remote event fired is the same as what the Server has. If it isn’t then you can mark them as an exploiter.

Print the data at both ends to debug it, also, I’d probably just send some unique identifier (id, name, …) and only that. The server knows the rest, as what you’re doing is very easy to exploit.

I did that, and somehow “Price” gets removed from the table (also at client side). The other values are still there tho.

That means the text fed to tonumber is not a number, so it returns nil.

1 Like

Ahhh, i’ll try to fix that, thanks!