local script in an image button under a shop frame. I right click the item to buy, it sends:
script.Parent.MouseButton2Click:Connect(function()
invMod:Purchase(player, script.Parent.Value.Value, script.Parent.ItemNameText.Text, 1)
task.wait()
invMod:RefreshSlots(script.Parent.ItemNameText.Text)
end)
which goes to my inventory module script under my Inventory screenGUI as it handles all my inventory functions:
function Inventory:Purchase(player,value, item, amt)
local iPurchase = RS.InventoryEvents.iPurchase
local data = Inventory:gSpend(value)
print(data)
if data == 0 then return
else
iPurchase:FireServer(item, amt, value)
local gUpdate = RS.CurrencyEvents.gUpdate
local data1 = gUpdate:InvokeServer(value)
local function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
local formattedData = comma_value(data1)
Player.PlayerGui.InventoryUI.PlayerInventory.Gold.Text = formattedData
end
end
the local data == inventory:gspend(value) server checks the profiles gold to make sure they have enough to purchase the item:
function Inventory:gSpend(value)
local gSpend = RS.CurrencyEvents.gSpend
gSpend:InvokeServer(value)
end
server side gspend invoke (where failure is i presume somehow)
gSpend.OnServerInvoke = function(Player,value)
local Profile = Manager.Profiles[Player]
if not Profile then return end
local gold = Profile.Data.Gold
print(gold,value)
local succorFail = {}
if gold >= value then
print("success")
local success = 1
table.insert(succorFail,success)
return succorFail
else
print("failure")
local failure = 0
table.insert(succorFail,failure)
return succorFail
end
end
and then that allows the rest of the purchase mod above to continue, which all works fine because i check if the data variable == 0 and continue, and since its nil it continues and purchases the item just fine, but it will just go into the negative gold and allow them to purchase anyway since the check is failing and im not getting my integer returns.