I made a module that will check if you have enough coins to buy the provided item, but it always says the error: "attempt to compare userdata with number" Here is the module script
module["PurchaseItem"] = function(item, cost, player)
local coin = player.leaderstats.Coins
if coin.Value >= cost then
coin.Value = coin.Value - cost
local Item = game.ReplicatedStorage[item]:Clone()
Item.Parent = player.PlayerGui.Menu.Inventory.Frame
end
end
And here is the script calling the function
Item.Common.Buy.MouseButton1Click:Connect(function()
Module["PurchaseItem"](Item.Common.Name, Item.Common.Price, script.Parent.Parent.Parent.Parent.Parent)
end)
