Attempt to compare nil <= number

I was trying to make a store system in my game, and I get this error that I don’t know how to fix. Here’s the code that’s erroring:

event4.OnServerEvent:Connect(function(player, pet, cost)
	print(cost)
	print(player.leaderstats.Cash.Value)
	if tonumber(player.leaderstats.Cash.Value) >= tonumber(cost.Value) then -- Errors here
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - cost
		petGive:Fire(player, pet)
	end
end)

Both print statements return what the values are supposed to be, not nil.

You should try removing the tonumber() functions, one of the values may be returning nil from that.

Edit: remove Value.

1 Like

So if the value is supposed to be cost, then what is cost.Value?

1 Like

Thank you, I was just working with so many variables so I kinda had a brain fart.

2 Likes

I ran the code again, and I’m kind of confused. The server code is mixing up the pet and cost variables while on the client everything’s fine

You’re not including player in FireServer(pet, cost) by accident, are you?

1 Like

Thank you! It works as intended now!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.