-
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.
-
What is the issue? Error “attempt to compare <= number”
-
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.