Please Help! "attempt to compare <= number"

  1. What do you want to achieve? When the player types an amount in a textbox, it sends the amount and item name to a server script, subtracts from the item value, and adds to the coin value accordingly.

  2. What is the issue? Error “attempt to compare <= number”

  3. What solutions have you tried so far? I’ve attempted to use the Assistant feature, but it doesnt work very well. Ive also done lots of printing values, and comparing different ways, all lead to the same issue. The server script is getting the Items name and the Amount number, but wont compare them.

Sell Handler (Server Side)

local rs = game:GetService("ReplicatedStorage")
local sellevent = rs:WaitForChild("Inventory").SellItem

sellevent.OnServerEvent:Connect(function(player, item, amount)

	local ItemValues = {
		["Stone"] = 5;
		["Coal"] = 8;
		["Iron"] = 10;
		["Copper"] = 9;
	}
	
	local stat = player.Stats[item]

	if stat.Value >= amount then
		print("suceses check")
		stat.Value -= amount
		player.leaderstats.Coins.Value += ItemValues[item] * amount
	end
end)

SellSender (Client Side)

local rs = game:GetService("ReplicatedStorage")
local event = rs:WaitForChild("Inventory").SellItem


local part = script.Parent
local player = game.Players.LocalPlayer
local item = script.Parent.Parent.Name

part.FocusLost:Connect(function(enterpressed)
	if enterpressed then
		local amount = part.Text
		
		print(amount, item)
		event:FireServer(item, amount)
	end
end)

The stats are Int values located under player.Stats, Ive been stuck on this for a couple hours and have no idea how to fix it. This is the first time I’ve used TextBoxes and tables so im way out of my comfort zone with this one.

1 Like

event:FireServer(item, tonumber(amount))

2 Likes

This worked! Thank you. What is the difference between tonumber(amount) and amount since they are both just numbers?

1 Like

the amount is a string because it’s from text which is a string, basically you need to convert it to a number

2 Likes

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