I am getting the error, “StackAmount is not a valid member of MeshPart “Stone”” when I pick up a stick then a stone, but if I pick up a stone then a stick then the error is, “StackAmount is not a valid member of Part “Stick””, and it prints 2, then 1 when I pick up the second item, so it destroys the part, then checks if the part has a value .
Error
or
Inside Items folder
Video of causing the error
LocalScript
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local mouse = player:GetMouse()
local debounce = false
local foundClosest = false
local alreadyLooped = false
local stopLooping = false
local available
local chosenSlot
function updateAvailableSlots()
available = {}
for i, v in pairs(script.Parent.ItemSlotsFrame:GetChildren()) do
if v:IsA("ImageButton") then
if v.IsAvailable.Value then
table.insert(available,v.SlotNumber.Value)
end
end
end
table.sort(available)
end
function findNextAvailableSlot()
return script.Parent.ItemSlotsFrame["ItemSlot"..available[1]]
end
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.E then
if not debounce then
debounce = true
if not gameProcessedEvent then
for i, v in pairs(workspace.Items:GetDescendants()) do
if v:FindFirstChild("IsItem") then
if foundClosest == false then
if (player.character.HumanoidRootPart.Position - v.Position).magnitude <= 8 then
for i, sameItem in pairs(script.Parent.ItemSlotsFrame:GetChildren()) do
if sameItem:IsA("ImageButton") then
if stopLooping == false then
if sameItem.Item.Value == v.Name then
print("1")
if sameItem.QuantityText.Quantity.Value < v.StackAmount.Value then
stopLooping = true
sameItem.QuantityText.Quantity.Value = sameItem.QuantityText.Quantity.Value + 1
sameItem.QuantityText.Text = sameItem.QuantityText.Quantity.Value
v:Destroy()
else
if sameItem.SlotFull == false then
sameItem.SlotFull.Value = true
updateAvailableSlots()
chosenSlot = findNextAvailableSlot()
chosenSlot.Image = v.ImageId.Value
chosenSlot.IsAvailable.Value = false
chosenSlot.Item.Value = v.Name
chosenSlot.QuantityText.Quantity.Value = chosenSlot.QuantityText.Quantity.Value + 1
chosenSlot.QuantityText.Text = chosenSlot.QuantityText.Quantity.Value
v:Destroy()
end
end
else
print("2")
if alreadyLooped == false then
updateAvailableSlots()
chosenSlot = findNextAvailableSlot()
chosenSlot.Image = v.ImageId.Value
chosenSlot.IsAvailable.Value = false
chosenSlot.Item.Value = v.Name
chosenSlot.QuantityText.Quantity.Value = chosenSlot.QuantityText.Quantity.Value + 1
chosenSlot.QuantityText.Text = chosenSlot.QuantityText.Quantity.Value
v:Destroy()
alreadyLooped = true
end
end
end
end
end
stopLooping = false
alreadyLooped = false
foundClosest = true
end
end
end
end
foundClosest = false
wait(1)
debounce = false
end
end
end
end)