This is most likely happening because you are not checking the players cash value before they purchase something. You would need to check how much cash the player has and if it is more than or equal to the cost of the item in the shop. I can only presume this is the cause as you have not showed your script yet
Ah, yes, you are correct, I found the currency part.
elseif event == "Buy_Item" then
local item = args[1]
local player_pounds = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Pounds")
if not player_pounds then warn("No pounds found for "..player.Name..", purchase failed") return end
local player_tools = player_tool_data[player]
local is_owned = player_tools[item.Name] --//See if the player already owns this tool
if not is_owned then --//Prevent duplicate purchases
player_pounds.Value = player_pounds.Value - item.Price.Value
player_tools[item.Name] = true
Give_Owned_Tools(player)
return true, player_tools
It does not appear you are checking the player can actually afford to purchase the item. You are always allowing the player to purchase regardless of how much cash they have. You need to check the players cash before purchase
elseif event == "Buy_Item" then
local item = args[1]
local player_pounds = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Pounds")
if not player_pounds or player_pounds.Value < item.Price.Value then warn("Not enough pounds for "..player.Name..", purchase failed") return end
local player_tools = player_tool_data[player]
local is_owned = player_tools[item.Name] --//See if the player already owns this tool
if not is_owned then --//Prevent duplicate purchases
player_pounds.Value = player_pounds.Value - item.Price.Value
player_tools[item.Name] = true
Give_Owned_Tools(player)
return true, player_tools
Make sure that the price value within the item exists for this line:
if not player_pounds or player_pounds.Value < item.Price.Value
You are making the player buy the item without checking if they actually have enough to buy it, resulting in the player’s cash becoming a negative value.
Also @varjoy, that won’t work. If the player were to play an extremely expensive item but doesn’t have enough to buy it, they would gain a lot of money.
try this:
elseif event == "Buy_Item" then
local item = args[1]
local player_pounds = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Pounds")
if not player_pounds or player_pounds.Value < item.Price.Value then warn("Not enough pounds for "..player.Name..", purchase failed") return end
local player_tools = player_tool_data[player]
local is_owned = player_tools[item.Name] --//See if the player already owns this tool
if not is_owned then --//Prevent duplicate purchases
if player_pounds.Value >= item.Price.Value then
player_pounds.Value = player_pounds.Value - item.Price.Value
player_tools[item.Name] = true
Give_Owned_Tools(player)
return true, player_tools
end
I would not recommend this solution. It does not prevent the purchase if the user does not have enough but it has the potential to lead to serious exploits where players could earn money simply by buying the most expensive item in the store.
For example: If I have 5 pounds and I purchase an item which costs 1,000 pounds then I will be left with 995 pounds.
local p = 5 -- p = +5
p = p - 1000 -- p = -995
p = math.abs(p) -- p = +995