Help With Equip Tool Function (Solved)

Alright everyone right now I have a slightly working inventory with stacks and it works perfectly fine but for mobile players there is a glitch where you cant eat or use the tools if you have a stack Ill show you what I mean.
Screen Recording 2023-10-07 at 2.25.35 PM.mov - Google Drive – the video
but it works perfectly fine when I use the computer keys to equip it.

local function handleEquip(tool)
	if tool.Parent == nil or tool.Parent == Backpack then
		Character.Humanoid:EquipTool(tool)
	elseif tool.Parent == Character then
		Character.Humanoid:UnequipTools()
	end
end

thats the line that is triggering the output for mobile

14:25:51.237  The Parent property of Cookie is locked, current parent: NULL, new parent DemonicPandazYT  -  Client - BackpackScript:30
2 Likes

thanks in advance by the way ill be looking into the error as well.

1 Like

try adding a task.wait() before equipping/unequipping the tool, my guess is that its trying to equip the tool too fast

2 Likes

but i am able to spam it perfectly fine with the computer keys i think its a bug in the code.

1 Like

it prevents me from eating a second stacked item, i can eat the first of both then it glitches.

1 Like

There’s not enough information. I can only guess that you’re trying to do something with an instance that’s already destroyed.

what info u need ill give it to u.

i have a whole video and listed the script and line with the issue.

For example, where does it call the function? All I know is that the tool is probably nil.

ur talking about calling the function as in the output?

Wherever you called the function with the tool parameter; handleEquip(nil)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then
		return
	end

	if KEY_DICTIONARY[input.KeyCode.Name] then
		local index = KEY_DICTIONARY[input.KeyCode.Name]
		local tool = items[index]

		if tool and not tool.Parent then
			for i, v in ipairs(stackedItems) do
				if tool.Name == v.Name then tool = v end
			end
		end

		if tool then
			handleEquip(tool)
		end
	end
end)

should i give u the whole script though or is this enough? i call the function when its clicked or when a key is clicked.

Just to confirm, equipping by clicking the gui will error, but not by pressing the key? Are both event using the same code?

yes correct and yeah they are the same code.

Can you send me that code if that is the code that leads to the error?

do u want me to send you the entire code?

If the code is connected to the tool then yes.

alright ima just send you the whole test server then because everything in there is linked. hold on give me a sec.

Is there anyone who can help me fix this issue?