Stumped on slot system

Hello developers,

I come to you with a bashed head and a broken keyboard. I am writing to you via my neuralink chip. All jokes aside, I’ve been stumped on this slot system i’ve been trying to get working. It seems that my slots do intially work, but then they don’t. What I mean, is that I will say pick up an item in slot number 2, but if I equip slot number 3 it will still equip that item, even if slot number 3 is empty.

Here’s a video of the issue:

and here are said scripts:
INVENTORY MANAGER [LOCALSCRIPT]

local SlotFrame = script.Parent:WaitForChild("Slots")
local ItemPickupFrame = script.Parent.ItemPickup
local ItemInfo = script.Parent.ItemInfo
local SlotScriptFolder = script.Parent.SlotScript

local TypeDisplay = ItemPickupFrame:WaitForChild("Type")
local NameDisplay = ItemPickupFrame:WaitForChild("Name")

local DescriptionDisplay = ItemInfo:WaitForChild("Description")
local ItemNameDisplay = ItemInfo:WaitForChild("Name")

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Remotes = RS:WaitForChild("RemoteEvents")
local Bindables = RS:WaitForChild("BindableEvents")

local PickupEvent = Remotes:WaitForChild("PickupItem")

local IntializeSlot = Bindables:WaitForChild("IntializeSlot")
local CallbackSlot = Bindables:WaitForChild("CallbackSlot")
local SecondaryCallbackSlot = Bindables:WaitForChild("SecondaryCallbackSlot")

local plr = Players.LocalPlayer
local mouse = plr:GetMouse()

local colorPalette = {Selected = Color3.fromRGB(57, 65, 31), NotSelected = Color3.fromRGB(30, 30, 30)}

local currentSlot = 1
local maxSlots = 3
local canSwitchSlot = true

local lastObject = nil
local currentObject = nil
local canPickup = true

local currentIdleAnimation = nil
local eventActive = false  -- Event starts inactive until explicitly activated

local SlotMatchups = {
	
	["SLOT 1"] = "EMPTY",
	["SLOT 2"] = "EMPTY",
	["SLOT 3"] = "EMPTY"
	
}


local function returnItemType(itemName)

	local itemList = {

		["Ibuprofen"] = "Consumables"

	}
	
	return itemList[itemName]

end

function returnCurrentSlot()
	
	return SlotFrame:FindFirstChild("Slot"..currentSlot)
	
end

function returnCurrentItem()
	
	local slot = returnCurrentSlot()
	
	local itemName = SlotMatchups[slot.SlotNumber.Text]
	
	if itemName == "EMPTY" then
		
		print("EMPTY SLOT")
		
		return "Fists"
		
	else
		
		return itemName	
	end
	
end


function switchSlot(toSlot : number, override : boolean)
	
	if currentSlot == toSlot and override == nil then return end
		
	if canSwitchSlot == false then return end
	if currentIdleAnimation then currentIdleAnimation:Stop() end
	if SlotScriptFolder:FindFirstChildOfClass("LocalScript") then SlotScriptFolder:FindFirstChildOfClass("LocalScript"):Destroy() end
	
	local findCurrentSlot = returnCurrentSlot()	
	
	if findCurrentSlot then findCurrentSlot.ContentFrame.BackgroundColor3 = colorPalette.NotSelected end
	
	local findNextSlot = SlotFrame:FindFirstChild("Slot"..toSlot)	
	
	if findNextSlot then findNextSlot.ContentFrame.BackgroundColor3 = colorPalette.Selected end
	
	local currentItem = returnCurrentItem()
	
	if currentItem ~= "Fists" and currentItem ~= "EMPTY" then
		
		local itemType = returnItemType(currentItem)
		
		local itemFolder = RS.ItemAssets:FindFirstChild(itemType):FindFirstChild(currentItem)
		local scriptForItem = itemFolder:WaitForChild(currentItem):Clone()
		scriptForItem.Parent = SlotScriptFolder
		
		local grabDescription = itemFolder.Description.Value
		
		ItemNameDisplay.Text = currentItem
		DescriptionDisplay.Text = grabDescription
		
		Remotes.DisconnectM6D:FireServer()
		
	end
	
	currentSlot = toSlot
	
end

function checkSlotEmpty(slotNumber : number)
	
	--// silly one line fullcheck :>
	
	if returnCurrentSlot(slotNumber):WaitForChild("ContentFrame").ItemName.Text == "EMPTY" then return true else return false end	
	
end

--// adding the slot switch

UIS.InputBegan:Connect(function(input, gpe)
	
	if gpe then return end
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		
		--// SLOT SECTION
		
		if input.KeyCode == Enum.KeyCode.One then
			
			switchSlot(1)
			
		elseif input.KeyCode == Enum.KeyCode.Two then
			
			switchSlot(2)
			
		elseif input.KeyCode == Enum.KeyCode.Three then
			
			switchSlot(3)
			
		end
		
		--// PICKUP SECTION
		
		if input.KeyCode == Enum.KeyCode.E and mouse.Target and canPickup then
			
			PickupEvent:FireServer(currentObject)
			
			lastObject = nil
			
		end
		
	end
	
end)

function runConsecutiveSlots(child)
	
	if checkSlotEmpty(2) == true then

		switchSlot(2)

		local newerSlotUi = returnCurrentSlot()

		newerSlotUi:WaitForChild("ContentFrame").ItemName.Text = "'"..child.Name.."'"

	elseif checkSlotEmpty(3) == true then

		switchSlot(3)

		local newerSlotUi = returnCurrentSlot()

		newerSlotUi:WaitForChild("ContentFrame").ItemName.Text = "'"..child.Name.."'"

	else

		print("bozo no slots are open ■■■■■■")

	end
	
end

function itemSlotsFull()
	
	if checkSlotEmpty(2) and checkSlotEmpty(3) then
		
		return true
		
	else 
		
		return false
		
	end
	
end

--// updating the slots

plr:WaitForChild("Inventory").ChildAdded:Connect(function(child)
	
	if child:IsA("Folder") then
		
		script.pickup:Play()
		
		local currentSlotUI = returnCurrentSlot()
		
		if currentSlotUI:FindFirstChild("exclusive") and child:FindFirstChild("IsMelee") then
			
			currentSlotUI:WaitForChild("ContentFrame").ItemName.Text = "'"..child.Name.."'"
			
		elseif currentSlotUI:FindFirstChild("exclusive") and not child:FindFirstChild("IsMelee") then
			
			--// garbo code im not tryna remove
			
			runConsecutiveSlots(child)
			
		elseif checkSlotEmpty(currentSlot) then
			
			currentSlotUI:WaitForChild("ContentFrame").ItemName.Text = "'"..child.Name.."'"
			SlotMatchups[currentSlotUI.SlotNumber.Text] = child.Name
			
			switchSlot(currentSlot, true)
			
		elseif not checkSlotEmpty(currentSlot) then
			
			print("full slot")		
			
		end
		
	end
	
end)

--// add slot intialization

IntializeSlot.Event:Connect(function(toConnect)
	
	print(toConnect)
	print("RECIEVE")

	Remotes.ConnectM6D:FireServer(toConnect)
	
	canSwitchSlot = false
	CallbackSlot:Fire()  -- Continue to fire if needed

end)

SecondaryCallbackSlot.Event:Connect(function(idleAnimation)
	
	print("Handling idle animation")
	currentIdleAnimation = idleAnimation
	canSwitchSlot = true
	
end)

--// adding the flippin item pickup idk

while task.wait(0.05) do
	
	if mouse.Target and mouse.Target.Parent:FindFirstChild("Pickup") then
			
		local item = mouse.Target.Parent
		
		currentObject = item
		
		ItemPickupFrame.Visible = true
		NameDisplay.Text = item.Name
		TypeDisplay.Text = item:WaitForChild("Type").Value
		
		--// activate highlight to signify ur looking at what
		item:WaitForChild("Selected").Enabled = true
		
		lastObject = item
		
		if not itemSlotsFull() or currentSlot == 1 then canPickup = false ItemPickupFrame.Unavilable.Visible = true	else canPickup = true ItemPickupFrame.Unavilable.Visible = false end
		
		
	else
		
		ItemPickupFrame.Visible = false
		
		if lastObject and lastObject:FindFirstChild("Selected") then lastObject:FindFirstChild("Selected").Enabled = false end
		
		currentObject = nil
		canPickup = false
		
	end
	
end

Ibuprofen (item script) [LOCALSCRIPT[

--// Default item script, for a consumable.

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player:LoadCharacter()

local RS = game:GetService("ReplicatedStorage")
local BindableEvents = RS:WaitForChild("BindableEvents")
local RemoteEvents = RS:WaitForChild("RemoteEvents")

local CreateNewVM = RemoteEvents:WaitForChild("CreateNewVM")

local IntializeSlot = BindableEvents:WaitForChild("IntializeSlot")
local CallbackSlot = BindableEvents:WaitForChild("CallbackSlot")
local SecondaryCallbackSlot = BindableEvents:WaitForChild("SecondaryCallbackSlot")

local ItemInformation = RS:WaitForChild("ItemAssets")
local Consumables = ItemInformation:WaitForChild("Consumables")
local CurrentItem = Consumables:FindFirstChild("Ibuprofen")

local Animations = CurrentItem:WaitForChild("Animations")
local Idle = Animations:WaitForChild("Idle")
local Equip = Animations:WaitForChild("Equip")

local newVM = nil
local newBase = nil

CreateNewVM:FireServer(CurrentItem)

CreateNewVM.OnClientEvent:Connect(function(returnedVM)
	
	print("VM RETURNED!")
	print(returnedVM)
	
	newVM = returnedVM
	
end)

print("getting there")

IntializeSlot:Fire(newBase)  -- First fire for initialization

CallbackSlot.Event:Connect(function(data)
	print("SENT")

	if data then
		print("Potential exploit detected!")
		
		print(data)
	end

	local humanoid = Char:WaitForChild("Humanoid")
	local LoadedEquip = humanoid:LoadAnimation(Equip)
	local LoadedIdle = humanoid:LoadAnimation(Idle)

	LoadedEquip:Play()
	LoadedEquip.Ended:Wait()

	LoadedIdle:Play()

	-- Fire the last time with the endLoop flag set to true
	SecondaryCallbackSlot:Fire(LoadedIdle)
end)

yeah ok it might be a lil big

Any help is appreciated (please),
OceanTubez

Forgot to mention, but the fists haven’t been created yet. So this pair of scripts only work for each other, but have the capability to be modular.