You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I am currently working on an inventory system, and am having an issue. A quantity variable that I use to defined how many stacked items there are loses its value when it is passed through a function. I would like to know how to keep the variable assigned throughout the entire script, or if I have made an error through my script. -
What is the issue? Include screenshots / videos if possible!
A quantity variable defined as folder(A folder for a slot in the player, inside an inventory folder).itemQuantity (the name of the int value). Quantity is an integer value inside this folder. I am not sure why, but when it passes through a text button’s MouseButton1Up function, its value becomes nil. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked through multiple DevForum posts, YouTube videos, stack overflow, and other sources but cannot seem to find anything to help my situation.
-- The section where quantity is defined:
local quantity
for i, itemChild in pairs(slots) do
if itemName == itemChild then
dup = true
folder = player:FindFirstChild("Inventory"):GetChildren()
for k, child in pairs(folder) do
if child:FindFirstChild(itemName) then
folder = child
end
end
local itemSlot = slotHolder:FindFirstChild(folder.Name)
quantity = folder.itemQuantity
quantity.Value += 1
itemSlot:FindFirstChild("quantityLabel").Text = "x"..quantity.Value
item.Parent = folder
end
end
-- The section where quantity loses its value
print(quantity) -- Quantity has a value here
local btnPressCD = false
slot.MouseButton1Up:Connect(function()
if btnPressCD == false then
btnPressCD = true
print(quantity) -- Quantity is nil here
darkFrame.Visible = true
drop1Btn.MouseButton1Up:Connect(function()
dropEvent:FireServer("1", quantity, slotFolder)
amtLabel.Text = quantity.Value
end)
end
I am not sure if this is caused by the fact it is a gui or something else. If any other information is needed or missing please ask so I can provide further context.