I am rewriting my code since I decided to go with ProfileService, and now my player’s inventories are stored in a table in their profile. I want to find the total amount of an item stored in the table profile, and multiply that by the amount it is worth, which is stored in a different table in a module in Replicated Storage.
I’m not getting any errors, but the players’ gold amount is not increasing, nor is the item amount being changed in their inventory.
Here is the script in the sell platform:
local sellPart = script.Parent
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local SystemsFolder = ServerStorage:WaitForChild("Systems")
local DataService = require(SystemsFolder.DataService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModulesFolder = ReplicatedStorage:WaitForChild("Modules")
local ItemData = require(ModulesFolder:WaitForChild("Harvestables"))
local function onTouch(playerTouched)
if playerTouched.Parent:IsA("Model") and
playerTouched.Parent:FindFirstChild("Humanoid")
then
local player = Players:GetPlayerFromCharacter(playerTouched.Parent)
if player then
local PlayerProfile = DataService:GetPlayerProfile(player)
local playerGold = PlayerProfile.Data.Gold
local Inventory = PlayerProfile.Data.Inventory
for items, amount in pairs(Inventory) do
local Quantity = amount
local Value = ItemData.Items[items].Worth
local totalSell = Quantity * Value
playerGold += totalSell
items = 0
PlayerProfile.Data.BagUsage = 0
end
end
if not player then return end
end
end
sellPart.Touched:Connect(onTouch)
Here is a snippet of the table in the module in Replicated Storage:
HarvestModule.Items = {
Berries = {
Name = "Berries",
LayoutOrder = 1,
Worth = 1,
},
I’ve messed around with the code a few times, a previous error was attempt to multiply number with table, got that to go away but I’m still not seeing the results I would like. Am I overthinking this? Or do I need to rethink how I’m handling the inventory or the item information?