StackAmount(An Int Value) is not a valid member of MeshPart "Stone" Error

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
Screenshot (43)
or
Screenshot (46)

Inside Items folder
Screenshot (47)

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)
1 Like

Assuming you are updating on client and checking on server the server cannot tell if it updated because you updated it the players computer, the client. You need to send the data to update to the server. A good rule of thumb is to get input on the client and process data and then replicate that data on the server.

I do not have a server script, this is the only script I do have and it is a local script.