How to tell if custom hotbar is full

  1. I would like to know how to tell if my hotbar is full or not.

2.The issue is when the hotbar is full, it returns the last slot instead of returning nil, to indicate that the hotbar is full and put the item in the inventory instead.

3.Tried checking to see if the slot was occupied, but it seemed to ignore it. The problem isn’t that the hotbar stacks beyond 6 slots, it doesn’t tell me if it’s full to put it in the inventory instead.

function Handler:GetEmptySlots()
	local PotentialSlots = {}
	for i, v in pairs(SlotData.Slots) do
		if v.CurrentTool == false then
			table.insert(PotentialSlots, v)
		end
	end

	local function lowestNumber()
		local Low = 6 --// Add num
		for i, v in pairs(PotentialSlots) do
			if v.Index < Low and v.CurrentTool == false then
				Low = v.Index
				print(v.CurrentTool)
			end
		end
		return Low
	end
	
	local num = tostring(lowestNumber())

    print(num)
	
	if num ~= nil then
		return SlotData.Slots["Slot"..num]
	else
		return nil
	end
end

Here’s the code that checks to see if the hotbar is full or not and which slot to put the weapon in.

1 Like

I ended up fixing it, it turns out the problem wasn’t with the script. All I had to do was check if the slot that the weapon was suppose to go in was occupied or not, I don’t know if this effect weapon dropping but it’ll have to work for now.

local SlotToGo = Handler:GetEmptySlots()
	local Match = game.ReplicatedStorage.weapons:FindFirstChild(Weapon.Name,true)
	
	local Data = require(Match.settings)
	
	if SlotToGo.CurrentTool ~= false then
		return nil
	end