Inventory wont work with custom character

My inventory system only works if i use my default avatar. If i try to use a customcharacter not only does my inventory not open but the tools i had in my inventory are also gone from the tool bar. I have no idea why this is happening. here is a portion of the script.

-- Inventory system, Dec 25 2021

local FADE_TIME = .2
local CATEGORY_NAMES = {"Melee", "Ranged", "Apparel", "Food", "Resources", "Misc"}

local inventoryGui = script.Parent.Parent
local slots = inventoryGui.Inventory.SlotFrame.Half.Slots:GetChildren()
local toolbar = inventoryGui.Toolbar.Holder
local player = game.Players.LocalPlayer
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")
local Run = game:GetService("RunService")

local GetThumbnails = RS:WaitForChild("GetThumbnails")
local Inventory = RS:WaitForChild("Inventory")
local Toolbar = RS:WaitForChild("Toolbar")
local BreakResource = RS:WaitForChild("BreakResource")
local thumbnailsReceived = false
local thumbnails = {}
GetThumbnails.OnClientEvent:Connect(function(thumbnailsList)
	for _, thumbnail in pairs(thumbnailsList) do
		thumbnails[thumbnail[1]] = {
			thumbnail[2], -- TextureId
			thumbnail[3], -- Level
			thumbnail[4], -- Rarity
			thumbnail[5], -- Desc
			thumbnail[6] -- Class
		}
	end
	thumbnailsReceived = true
end)
GetThumbnails:FireServer()

local rarityColors = nil
local rarityNames = nil
local function getRarityColor(rarityNum)
	if rarityColors == nil then
		repeat wait() until RS:FindFirstChild("RarityColors") ~= nil
		rarityColors = RS.RarityColors:GetChildren()
	end
	for _, color in pairs(rarityColors) do
		if tonumber(string.sub(color.Name, 1, 1)) == rarityNum then
			return color.Value
		end
	end
end
local function getRarityName(rarityNum)
	for _, color in pairs(rarityColors) do
		if tonumber(string.sub(color.Name, 1, 1)) == rarityNum then
			return string.sub(color.Name, 3)
		end
	end
end

local categories = {{}, {}, {}, {}, {}, {}, {}} -- Storage here

local generating = false
local generateInfo = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local function generateInventory(categoryNum, arrowButton)
	if thumbnailsReceived == false then
		repeat wait() until thumbnailsReceived == true
	end
	if generating == true then
		repeat wait() until generating == false
	end
	generating = true
	for tabNum = 1, 6 do
		local tab = inventoryGui.Inventory.Tabs.Half.TabArea[tostring(tabNum) .. "-" .. CATEGORY_NAMES[tabNum]]
		if tabNum == categoryNum then
			local colorShow = TS:Create(tab, generateInfo, {ImageColor3 = Color3.new(1, 1, 1)})
			colorShow:Play()
			tab.Parent.Parent.Line.Underline:TweenPosition(UDim2.new(.167 * (tabNum - 1), 0, 0, 0),
				Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
			tab.Parent.Title.Text = CATEGORY_NAMES[tabNum]
		else
			local colorFade = TS:Create(tab, generateInfo, {ImageColor3 = Color3.fromRGB(52, 53, 61)})
			colorFade:Play()
		end
	end
	if arrowButton ~= nil then
		spawn(function()
			arrowButton.Icon:TweenSizeAndPosition(
				UDim2.new(.8, 0, .8, 0),
				UDim2.new(.1, 0, .1, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Linear,
				.05,
				true
			)
			wait(.05)
			arrowButton.Icon:TweenSizeAndPosition(
				UDim2.new(.9, 0, .9, 0),
				UDim2.new(.05, 0, .05, 0),
				Enum.EasingDirection.In,
				Enum.EasingStyle.Linear,
				.05,
				true
			)
		end)
	end
	for slotNum = 1, #slots - 1 do
		local slot = slots[1].Parent[tostring(slotNum)]
		local slotInfo = categories[categoryNum][slotNum]
		if slotInfo ~= nil then -- Slot exists
			local thumbnailId = thumbnails[slotInfo[1]]
			if #thumbnailId[1] > 0 then -- Thumbnail exists
				slot.Button.Image = thumbnailId[1]
				slot.Text.Visible = false
			else -- Thumbnail does not exist
				slot.Button.Image = ""
				slot.Text.Text = slotInfo[1]
				slot.Text.Visible = true
			end
			slot.Amount.Text = slotInfo[2]
			slot.Amount.Visible = true
			slot.Button.BackgroundColor3 = getRarityColor(thumbnailId[3])
		else -- Slot does not exist
			slot.Text.Visible = false
			slot.Button.Image = ""
			slot.Amount.Visible = false
			slot.Button.BackgroundColor3 = Color3.fromRGB(39, 38, 48)
		end		
	end
	
	-- generate toolbar
	for slotNum = 1, 3 do
		if slotNum == categories[7][1] then
			toolbar["Slot" .. tostring(slotNum)].UIStroke.Color = Color3.new(1, 1, 1)
		else
			toolbar["Slot" .. tostring(slotNum)].UIStroke.Color = Color3.fromRGB(64, 64, 72)
		end
		local info = categories[7][slotNum + 1]
		if info ~= nil then
			toolbar["Slot" .. tostring(slotNum)].Image = thumbnails[info[1]][1]
			toolbar["Slot" .. tostring(slotNum)].BackgroundColor3 = getRarityColor(thumbnails[info[1]][3])
			if #thumbnails[info[1]][1] <= 0 then
				toolbar["Slot" .. tostring(slotNum)].Text.Visible = true
				toolbar["Slot" .. tostring(slotNum)].Text.Text = info[1]
			else
				toolbar["Slot" .. tostring(slotNum)].Text.Visible = false					
			end
		else
			toolbar["Slot" .. tostring(slotNum)].Image = ""
			toolbar["Slot" .. tostring(slotNum)].Text.Visible = false
			toolbar["Slot" .. tostring(slotNum)].BackgroundColor3 = Color3.fromRGB(39, 38, 48)
		end
	end
	generating = false
end

local currentCategory = 1

local died = false
local fade = inventoryGui.Fade
local fadeInfo = TweenInfo.new(FADE_TIME, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local fadeIn = TS:Create(fade, fadeInfo, {BackgroundTransparency = 0})
local fadeOut = TS:Create(fade, fadeInfo, {BackgroundTransparency = 1})

local function setGuiClone(character)
	died = false
	local humanoid = character:WaitForChild("Humanoid")
	character:WaitForChild("Head")
	if not character.Head:FindFirstChildOfClass("Decal") then
		repeat wait() until character.Head:FindFirstChildOfClass("Decal") ~= nil
	end
	character.Archivable = true
	local clone = character:Clone()
	character.Archivable = false
	clone:SetPrimaryPartCFrame(workspace.InventoryArea.DummyAnchor.CFrame)
	clone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	clone.Parent = workspace.InventoryArea
	local idle1 = clone.Humanoid:LoadAnimation(script.Idle1)
	local idle2 = clone.Humanoid:LoadAnimation(script.Idle2)
	local currentAnim = idle1
	
	character:WaitForChild("Humanoid").Died:Connect(function()
		died = true
		if inventoryGui.Inventory.Visible == true then
			fadeIn:Play()
			wait(FADE_TIME)
			clone:Destroy()
			inventoryGui.Inventory.Visible = false
			inventoryGui.Header.Visible = false
			toolbar.Parent.DescShow.Visible = false
			script.Parent.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
			script.Parent.Text = "Open Inventory"
			local camera = workspace.CurrentCamera

			camera.CameraType = Enum.CameraType.Custom
			if player.Character == nil then
				player.CharacterAdded:wait() -- If the player has died, wait for respawn
				repeat wait() until player.Character:FindFirstChild("Humanoid") ~= nil

			end
			camera.CameraSubject = player.Character.Humanoid	
			fadeOut:Play()
		end
	end)

	local count = 0
	spawn(function()
		currentAnim:Play()
		while wait(4) do
			if not character then
				break
			end
			currentAnim:Stop()
			if count >= 4 then
				currentAnim = idle2
				count = 1
			else
				currentAnim = idle1
				count = count + 1
			end
			currentAnim:Play()
		end
	end)
end
if player.Character then
	setGuiClone(player.Character)
end
player.CharacterAdded:Connect(function(character)
	setGuiClone(character)
end)

not sure if the problem lies within this part of the script but i hope someone can help as this is completely holding me back from continuing with the game.

Is there any error statements that it gives?

Nope. No error or anything in the output.