Sell system issues

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

-- Connections

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! :stuck_out_tongue:

Any help? Thanks!

I gotchu lil bruh.

So in your module script ur gonnaa use that table to make functions not store values. Make a separate table 4 that.

----- Sellscript you’re going to swap “Swap orePrice = orePrices[ore]” with :arrow_down:

local orePrice = orePrices.CheckValue(ore)

— Module script

Module = {}

local Ores = {Stone = 1}

function Module.CheckValue(Ore)

----That should work for you.

1 Like

Errored again.

Module code did not return exactly one value

Remember to always return the module on the last line of it’s code, use this on the last line:

return Module
1 Like

Still getting the same error as the one I described in the post unfortunately.

I tried printing what the OresPrice is and it seems to be printing nil

Have you tried printing the ore and quantity variables? Looping through an array makes the ore variable just a number, and that’s why it returns nil for the orePrices[ore] variable.