-
What do you want to achieve?
I am trying to make a script that calculates how much of one item can be crafted (entirely for display purposes, as an actual script will deal with making sure and all that.) -
What is the issue?
It’s only adding one of the “requiredMaterial” values as a table, here’s what it’s printing:
Actual Print
{
[1] = {
["Clay"] = 0
},
[2] = {
["Tin Ore"] = 1
}
Here’s what it should be printing:
Intended Print
{
[1] = {
["Clay"] = 0,
["Sand"] = 1
},
[2] = {
["Tin Ore"] = 1
}
-
What solutions have you tried so far?
I’ve tried changing all sorts of code and I’ve tried looking for things on the forums with no luck. I’m not sure where the problem is at this point. I think this might be important to mention, but I’m not sure, when I usedtable.insert
instead oft[loopNumber] = {}
, “Sand,” the missing value, was inserted, but again, it had more tables than it should of (3 instead of the current possible max of 2).
local t = {}
--there's code between all this, but i don't believe it's necessary to show it all
for loopNumber = 1,math.max(nums) do --the highest "nums" can be is 2
for requiredMaterial,amount in pairs(array[loopNumber]) do --this gets a bunch of names and amounts to be inserted into the problematic table
if loopNumber == nums then
t[loopNumber] = {} --creates a table with the same name as the number of the loop, i tried a similar thing with table.insert but it created more tables than it's intended to
local playerAmount = Inventory:FindFirstChild(requiredMaterial) --i believe this is pointless to put when it comes to asking for help for the problem, but i'll put it here just in case
local craftableAmount = 0
if playerAmount then
craftableAmount = math.floor(playerAmount.Value / amount) --i believe this is pointless to put when it comes to asking for help for the problem, but i'll put it here just in case
end
t[loopNumber][requiredMaterial] = craftableAmount
end
end
end
print(t)
I’m happy for any and all advice!