Hello,
i've recently been working on my first game and created an inventory system in it. I have one major problem though and its that it wont take a tool from the inventory and place it in your backpack.
local player = game.Players.LocalPlayer local playerInv = game.Players.LocalPlayer:WaitForChild("SpellList") local backpack = player.Backpack:GetChildren() local itemName = script.Parent.Parent.ItemName local itemToCheck = player.SpellList:FindFirstChild(itemName.Value) if itemToCheck then local itemToEquip = player.SpellList:WaitForChild(itemName.Value) local itemInBP = backpack:FindFirstChild(itemName.Value) if #backpack < 2 and not itemInBP then local equipToBP = itemToEquip:Clone() equipToBP.Parent = player.Backpack elseif #backpack >= 2 then print("Unequip an item!") elseif itemInBP then itemInBP:Destroy() end end
inside of the gui that i created for the items there is a string value that gets changed to the tool's name so that i can use FindFirstChild() to search for whatever the tools name is in their inventory folder named "SpellList". The console isn't spitting out any errors and when i click the equip button nothing happens. the itemInBP and #backpack are to check if the player has more than 2 items equipped and if they already have the item equipped.
I think you just wasn't updating after they clicked it, try:
local player = game.Players.LocalPlayer local playerInv = game.Players.LocalPlayer:WaitForChild("SpellList") local backpack = player.Backpack:GetChildren() local itemName = script.Parent.Parent.ItemName local itemToCheck = player.SpellList:FindFirstChild(itemName.Value) local EquipRequest = player.SpellList:WaitForChild(itemName) EquipRequest.Changed:Connect(function() if itemToCheck then local itemToEquip = player.SpellList:WaitForChild(itemName.Value) local itemInBP = backpack:FindFirstChild(itemName.Value) if #backpack < 2 and not itemInBP then local equipToBP = itemToEquip:Clone() equipToBP.Parent = player.Backpack elseif #backpack >= 2 then print("Unequip an item!") elseif itemInBP then itemInBP:Destroy() end end end)
Let me know if this works ~nevan
So im a big dumb. I never put it to activate the script if the button is pressed
Its fully working now.