Inventory slot selection suddenly stopped working

I made a inventory slot selection system where it adds a click function on each inventory slot. It was working perfectly fine a few hours ago, but now the click function isnt firing at all.

Client inventory script:

local inventory = {}

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer

local ts = game:GetService("TweenService")
local StarterGui = game:GetService("StarterGui")

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local changeSlotRemote = remotes:WaitForChild("UpdateInventorySlots")
local getInv = remotes:WaitForChild("GetPlayerInventory")

local popup = require(ReplicatedStorage:WaitForChild("ClientModules"):WaitForChild("PopupPrompts"))
local launch = require(ReplicatedStorage:WaitForChild("ClientModules"):WaitForChild("LaunchClient"))
local menu = require(ReplicatedStorage:WaitForChild("ClientModules"):WaitForChild("MenuClient"))

inventory.inv = nil

inventory.Ready = false
inventory.inventoryGui = nil

local selectedSlot = nil
local defaultSelectedBlock = ReplicatedStorage:WaitForChild("Blocks"):WaitForChild("Wood_Planks")
local defaultBlockId = defaultSelectedBlock:GetAttribute("BLOCKID")
inventory.selectedBlock = defaultSelectedBlock

local slotCache = {}
local _, _, defaultGrayV = Color3.fromRGB(71, 71, 71):ToHSV()

local clearDebounce = false

local function findBlockName(blockId)
	local blockFolder = game.ReplicatedStorage.Blocks
	for _, block in pairs(blockFolder:GetChildren()) do
		local id = block:GetAttribute("BLOCKID")
		if id then
			if id == blockId then
				return {DisplayName = block:GetAttribute("DisplayBlockName"), Block = block}
			end
		end
	end
end

local function selectSlot(slot, highlightColor, holdingFrame, block)
	print(slot)
	if not slot or not highlightColor or not holdingFrame then return end

	inventory.selectedSlot = slot

	for _, v in pairs(holdingFrame:GetChildren()) do
		if v:IsA("Frame") and v:FindFirstChild("Stroke") then
			local blockId = tonumber(string.match(v.Name, "%d+"))
			if blockId then
				local blockData = findBlockName(blockId)
				if blockData then
					local invColor = blockData.Block:GetAttribute("InventoryColor")
					if invColor then
						local h, s = invColor:ToHSV()
						local greyColor = Color3.fromHSV(h, s, defaultGrayV)
						v.Stroke.Color = greyColor
					end
				end
			end
		end
	end

	local stroke = slot:FindFirstChild("Stroke")
	if stroke then
		stroke.Color = highlightColor
	end

	if block then
		inventory.selectedBlock = block
	end
end

local function AddSlot(blockId, amount)
	print(blockId, amount)
	if not blockId or not amount then return end

	local inventoryGui = inventory.inventoryGui
	if not inventoryGui then return end
	if not inventoryGui:IsA("ScreenGui") then return end

	local frame = inventoryGui:WaitForChild("Frame")
	local list = frame:WaitForChild("InventoryList")
	local scrollingframe = list:WaitForChild("ScrollingFrame")
	local holdingframe = scrollingframe:WaitForChild("HoldingFrame")

	local blockData = findBlockName(blockId)
	if not blockData then return end

	local blockName = blockData.DisplayName
	local block = blockData.Block

	local function findCurrentSlot()
		for i,v in pairs(holdingframe:GetChildren()) do
			if v:IsA("Frame") then
				if string.find(v.Name, blockId) then
					return v
				end
			end
		end
	end

	local slot = findCurrentSlot() or script.InventorySlot:Clone()
	slotCache[blockId] = slot
	slot.Name = "Slot_"..blockId
	slot.BlockName.Text = blockName
	slot.Amount.Text = amount

	local color = block:GetAttribute("InventoryColor")

	if color then
		local h, s, v = color:ToHSV()
		local _, _, grayV = Color3.fromRGB(71,71,71):ToHSV()

		local newColor = Color3.fromHSV(h, s, grayV)

		slot.Stroke.Color = newColor
	end

	local function getBiggestNumberFromSize(vec)
		local biggest = vec.X
		if vec.Y > biggest then biggest = vec.Y end
		if vec.Z > biggest then biggest = vec.Z end
		return biggest
	end

	local viewport = script.BlockIcon:Clone()
	local viewportBlock = block:Clone()
	local orientation, size = viewportBlock:GetBoundingBox()

	local cameraDistance = getBiggestNumberFromSize(size) * 1.5

	viewportBlock:PivotTo(CFrame.new(0,0,cameraDistance)*CFrame.Angles(0,math.rad(45),math.rad(45)))
	viewportBlock.Parent = viewport

	local iconHolder = slot:FindFirstChild("IconHolder")
	if iconHolder then
		viewport.Parent = slot.IconHolder
	end

	local button = slot:FindFirstChild("Button")
	if button then
		print(button)
		print(slot)
		button.MouseButton1Click:Connect(function()
			print("click")
			selectSlot(slot, color, holdingframe, block)
		end)
	end

	if blockId == defaultBlockId then
		selectSlot(slot, color, holdingframe, block)
	end

	slot.Parent = holdingframe
end

local function updateSlot(blockId, amount, mode)
	local inventoryGui = inventory.inventoryGui
	if not inventoryGui then return end
	if not inventoryGui:IsA("ScreenGui") then return end

	local frame = inventoryGui:WaitForChild("Frame")
	local list = frame:WaitForChild("InventoryList")
	local scrollingframe = list:WaitForChild("ScrollingFrame")
	local holdingframe = scrollingframe:WaitForChild("HoldingFrame")

	local slot = slotCache[blockId]
	if not slot then AddSlot(blockId, amount) return end

	if mode == "rejected" then
		task.spawn(function()
			slot.Amount.TextColor3 = Color3.fromRGB(255,0,0)
			task.wait(0.3)
			slot.Amount.TextColor3 = Color3.fromRGB(255, 255, 255)
		end)
	elseif amount then
		slot.Amount.Text = amount
	end
end

local function removeRemainingSlots(Inventory)
	local inventoryGui = inventory.inventoryGui
	if not inventoryGui then return end
	if not inventoryGui:IsA("ScreenGui") then return end

	local frame = inventoryGui:WaitForChild("Frame")
	local list = frame:WaitForChild("InventoryList")
	local scrollingframe = list:WaitForChild("ScrollingFrame")
	local holdingframe = scrollingframe:WaitForChild("HoldingFrame")

	local slotsToRemove = {}
	for _, child in pairs(holdingframe:GetChildren()) do
		if child:IsA("Frame") and string.find(child.Name, "Slot") then
			local number = tonumber(string.match(child.Name, "%d+"))
			if number then
				table.insert(slotsToRemove, child)
			end
		end
	end

	local function findSlot(blockId)
		local slot = slotCache[blockId]
		return slot
	end

	if Inventory or #Inventory > 0 then
		for _, entry in pairs(Inventory) do
			if entry.BLOCKID then
				local blockId = entry.BLOCKID
				local slot = findSlot(blockId)
				if slot then
					table.remove(slotsToRemove, table.find(slotsToRemove, slot))
				end
			end
		end
	end

	for _, slot in pairs(slotsToRemove) do
		if typeof(slot) == "Instance" then
			if slot == inventory.selectedSlot then
				local defaultSelectedFrame = holdingframe:FindFirstChild("Slot_"..defaultSelectedBlock:GetAttribute("BLOCKID"))
				if defaultSelectedFrame then
					selectSlot(slot, defaultSelectedBlock:GetAttribute("InventoryColor"), holdingframe, defaultSelectedBlock)
				else
					selectedSlot = false
					inventory.selectedBlock = defaultSelectedBlock
				end
			end
			slot:Destroy()
		end
	end
end

function inventory:Start()
	self.inventoryGui = script.Inventory:Clone()
	self.inventoryGui.Enabled = false
	self.inventoryGui.Parent = player:FindFirstChild("PlayerGui") or player:WaitForChild("PlayerGui")

	if UserInputService.TouchEnabled then
		local frame = self.inventoryGui:FindFirstChild("Frame")
		if frame then
			frame.Position = UDim2.new(1, -10, 0.4, -10)
			frame.UIAspectRatioConstraint:Destroy()
			frame.Size = UDim2.new(0.2,30,0.7,-10)
		end
	end

	inventory.inv = getInv:InvokeServer()
	if inventory.inv then
		for i, v in pairs(inventory.inv) do
			AddSlot(v.BLOCKID, v.AMOUNT)
		end
	end

	local frame = self.inventoryGui:FindFirstChild("Frame")
	if not frame then return end
	local settingsFrame = frame:FindFirstChild("SettingsFrame")
	if not settingsFrame then return end
	local settingsbutton = frame:FindFirstChild("OpenSettings")
	if not settingsbutton then return end

	settingsbutton.MouseButton1Click:Connect(function()
		settingsFrame.Visible = not settingsFrame.Visible
	end)

	local clear = frame:FindFirstChild("Clear")
	if not clear then return end

	local function confrimClear()
		local clearFunc = remotes:WaitForChild("ClearAllServer"):InvokeServer()
		if clearFunc then
			clearDebounce = false
		end
	end

	local function cancelClear()
		clearDebounce = false
	end

	clear.MouseButton1Click:Connect(function()
		if not clearDebounce then
			clearDebounce = true
			popup:Create("Yes/No", "Are you sure you want to clear your entire plot?", confrimClear, cancelClear)
		end
	end)
end

function inventory:UpdateSlotState(blockId, mode)
	updateSlot(blockId, nil, mode)
end

function inventory:Toggle(toggle)
	local inventoryGui = self.inventoryGui
	if not inventoryGui then return end
	if not inventoryGui:IsA("ScreenGui") then return end

	local pgui = player:FindFirstChild("PlayerGui") or player:WaitForChild("PlayerGui")
	local playerList = pgui:FindFirstChild("PlayerList") or pgui:WaitForChild("PlayerList")
	print(toggle)
	if toggle == false then
		print("1")
		playerList.Enabled = false
		
		local function checkIfLaunched(team)
			print(team)
			if not team then return end
			local plots = workspace:WaitForChild("Plots")
			local teamPlot = plots:FindFirstChild(team.Name)
			if not teamPlot then return end
			local launchedVal = teamPlot:FindFirstChild("Launched")
			if not launchedVal then return end

			return launchedVal.Value
		end
		
		print("2")

		local team = player.Team
		local launched = checkIfLaunched(team)
		
		print("got past")
		
		if not launched then
			print("3")
			launch.Show()
			menu.Show()
		else
			print("4")
			launch.Hide()
			menu.Hide()
			menu.CloseFrame()
		end
		
		for _, slot in pairs(slotCache) do
			if slot.Amount then
				slot.Amount.TextColor3 = Color3.fromRGB(255, 255, 255)
			end
		end
	else
		playerList.Enabled = true
		launch.Hide()
		menu.Hide()
		menu.CloseFrame()
	end

	inventoryGui.Enabled = toggle
end

remotes:WaitForChild("UpdateInventorySlots").OnClientEvent:Connect(function(blockId, amount)
	updateSlot(blockId, amount)
end)

local updateCooldown = false

return inventory

The first slot added works but not the second.

I added checks if the slot and button exists and it does. But when I click on the button it doesnt print ‘clicked.’

I also tried disabling this function and nothing changed:

local function checkIfLaunched(team)
			--print(team)
			--if not team then return end
			--local plots = workspace:WaitForChild("Plots")
			--local teamPlot = plots:FindFirstChild(team.Name)
			--if not teamPlot then return end
			--local launchedVal = teamPlot:FindFirstChild("Launched")
			--if not launchedVal then return end

			return false
		end

The only changes to this script today was add these:

	if not launched then
			print("3")
			launch.Show()
			menu.Show()
		else
			print("4")
			launch.Hide()
			menu.Hide()
			menu.CloseFrame()
		end
else
		playerList.Enabled = true
		launch.Hide()
		menu.Hide()
		menu.CloseFrame()
	end

I tried commenting those out but it still didnt do anything.