Hey, it’s pretty late at night and I have a headache so I’m gonna make this post short and simple.
I’m creating a sell system for a custom inventory and I keep getting this error no matter what I try. I have a limited knowledge of ModuleScripts hence why I’ve been using them a lot recently.
Sell Script
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- Variables
local scriptableObjects = workspace.ScriptableObjects
local sellPart = scriptableObjects.SellPart
local orePrices = require(ReplicatedStorage.OrePrices)
local totalPrice = 0
-- Functions
local function SellInventory(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local inventory = player.Inventory
for ore, quantity in pairs(inventory:GetChildren()) do --// looping through players inventory
local orePrice = orePrices[ore] --// getting price of a single item
local priceOfInventory = orePrice * quantity --// getting the total price of users' items
totalPrice = totalPrice + priceOfInventory --// adding it to the total value
end
print(totalPrice)
end
end
end
-- Connections
sellPart.Touched:Connect(SellInventory)
OreData module
local module = {
["Stone"] = 1
}
return module
The error is: attempt to perform arithmetic (mul) on nil and Instance
Forgot to mention it’s line 22 which is local priceOfInventory = orePrice * quantity
, my bad!
Any help? Thanks!