I’m trying to make a custom inventory system, my tool doesn’t equip the first time when its called however, it equips the second time.
function Inventory:EquipTool(player: Player, itemName: string)
print("equip tool function")
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid") or character:WaitForChild("Humanoid")
local toolToEquip = player.Backpack:FindFirstChild(itemName)
if toolToEquip then
humanoid:UnequipTools()
task.defer(function()
task.wait(0.2)
if toolToEquip.Parent == player.Backpack then
humanoid:EquipTool(toolToEquip)
else
warn("Tool was moved before equipping:", itemName)
end
end)
else
warn("Tool not found or invalid:", itemName)
end
end