Please let me know if this is the wrong category, however I’m pretty sure this is the right one.
local Recipe = CraftingRecipes[InformationGiven]
local InventoryRecord = Inventories[player.UserId]
warn("inventory",Inventories[player.UserId])
warn("recipe",CraftingRecipes[InformationGiven])
for SlotIDX, Slot in pairs(InventoryRecord[1]) do
local SlotName, SQuantity = FindSlotNameAndQuantity(Slot)
local SlotNameFoundIDX = table.find(IngredientNames, SlotName)
if SlotNameFoundIDX then
SlotNameFoundIDX += 3
local IngredientName, IQuantity = FindSlotNameAndQuantity(Recipe[SlotNameFoundIDX])
warn("ingredient info", IngredientName, IQuantity)
if SQuantity > IQuantity then
table.remove(Recipe, SlotNameFoundIDX)
table.remove(IngredientNames, SlotNameFoundIDX)
elseif SQuantity < IQuantity then
Recipe[SlotNameFoundIDX] = tostring(SQuantity - IQuantity)..IngredientName
InventoryRecord[1][SlotIDX] = "Empty"
else
table.remove(Recipe, SlotNameFoundIDX)
table.remove(IngredientNames, SlotNameFoundIDX)
InventoryRecord[1][SlotIDX] = "Empty"
end
end
end
warn("inventory",Inventories[player.UserId])
warn("recipe",CraftingRecipes[InformationGiven])
Im trying to make a crafting system for my game, which requires me to get copies of a crafting recipe and the players’ inventory (obviously) to see if the player has the items required to make the item. However, the problem is that when I create copies of the original variables, they seem to directly affect the original variable when I interact with the copy later??? what confuses me even more is that the crafting recipe continues to be modified, even when I set it to become readonly earlier in the code???
Original variables (storing the actual copies):
- Inventories[player.UserId]
- CraftingRecipes[InformationGiven]
Copy variables (storing copies that I edit to make the calculations):
- InventoryRecord
- Recipe
BEFORE ANY CHANGES (FIRST 2 WARNS)
AFTER THE CHANGES (LAST 2 WARNS)
keep in mind in both of these screenshots these are supposedly the originals, not the copy variables I edit in my code. I am also sure that I am editing the variables I make as copies, and not the main ones, as I have tested by removing any edits to the copies and only then no changes are made.