Code Dosen't Work

Soo I Am Making a Inventory System And I Made It So That The Player Have To Enter A Number To switch the Item they want to the hotbar and cant figure out how

this is the model file its a rbxm file you can download it for more info:
HotBarInv.rbxm (18.8 KB)

please dont say i didnt gave alot of info the model above is almost everything anyone would need to solve my problem

script for changing tables of hotbar to inv

	local timeout = false
	for i,v in pairs(script.Parent:GetDescendants()) do
		if v:FindFirstChild("IsItem") and v.Parent ~= script then
			v.MouseButton1Click:Connect(function()
				script.Parent.Change.Visible = true
				script.Parent.Change.Title.Text = "Change "..v.Name
				script.Parent.Change.Cancel.MouseButton1Click:Connect(function()
					script.Parent.Change.Visible = false
				end)
				script.Parent.Change.Confirm.MouseButton1Click:Connect(function()
					if not timeout then
						timeout = true
						local Slot = script.Parent.Change.Input.Text
						if #Slot == 0 then return end
						if v.Parent == script.Parent.Inventory.StoreArea then

						else					
							local object = table.find(Tools,game.Players.LocalPlayer.Backpack[v.Name])
							local Obj = Inventory[Slot]
							table.remove(Tools,table.find(Tools,game.Players.LocalPlayer.Backpack[v.Name]))
							table.insert(Inventory,Slot,object)
							if Obj then
								table.remove(Tools,Slot)
								table.insert(Inventory,#Inventory,Obj)
							end
							updatehotbar()
						end
						wait(0.5)
						timeout = false
					end
				end)
			end)
		end
	end

Please help i need it right now sometimes it gives error other times no error

Whole Code
local Tools = {}
local MaxINV = 3
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
local Num = 0
local Inventory = {}
local InvFilled = false
local HotFilled = false
local db = false

local Restrict = 0

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(function()
	if not db then 
		db = true 
		if Mouse.Target ~= nil and Mouse.Target.Parent:IsA("Tool") then
			if not InvFilled then
				print("Can Pick")
				Mouse.Target.Parent.Parent = game.Players.LocalPlayer.Backpack
			else
				Restrict = 3
				print("Cant Pick Inventory Filled")
			end
		end
		wait(0.1)
		db = false
	end
end)

local NumToWords = {
	[1] = "One",
	[2] = "Two",
	[3] = "Three",
	[4] = "Four",
	[5] = "Five",
	[6] = "Six",
	[7] = "Seven",
	[8] = "Eight",
	[9] = "Nine",
	[10] = "Zero",
}
local messdisplayed = false

-- Updates Hotbar
local function updatehotbar()
	-- Deletes Old Stuff
	for i,v in pairs(script.Parent.Frame:GetChildren()) do
		if v:IsA("TextButton") then
			v:Destroy()
		end
	end
	-- Cap
	if #Tools > 10 then
		table.insert(Inventory,#Inventory+1,Tools[#Tools])	
		table.remove(Tools,#Tools)
		if #Inventory < MaxINV then
			local temp = script.Temp:Clone()
			temp.Parent = script.Parent.Inventory.StoreArea
			temp.Text = Inventory[#Inventory].Name
			temp.Num:Destroy()
			temp.Name = Inventory[#Inventory].Name
			InvFilled = false
		else
			local object =	Inventory[#Inventory]
			table.remove(Inventory,#Inventory)		
		end
		if #Inventory > MaxINV-2 then
			Restrict = 2
			print("Inventroy Filled ", Inventory)
			InvFilled = true
		end
	elseif #Tools == 10 then
		if not messdisplayed then
			messdisplayed = true
			Restrict = 1
			HotFilled = true
		end
	else
		HotFilled = false
	end
	-- Makes Stuff
	for i,v in pairs(Tools) do
		for _,L in pairs(script.Parent.Frame:GetChildren()) do
			if L.Name == v.Name then
				L:Destroy()
			end
		end
		local temp = script.Temp:Clone()
		if #Tools < 11 then
			temp.Parent = script.Parent.Frame
		end
		if i == 10 then 
			temp:WaitForChild('Num').Text = 0
		else
			temp:WaitForChild('Num').Text = i
		end
		temp.Text = v.Name
		temp.Name = v.Name
	end
	for i,v in pairs(script.Parent.Inventory.StoreArea:GetChildren()) do
		if v:IsA("TextButton") then
			local BoolValue = Instance.new("BoolValue",v)
			BoolValue.Name = "InventroyItem"
			for u,c in pairs(v:GetChildren()) do
				if c:FindFirstChild("InventoryItem") and c.InventoryItem ~= BoolValue then
					print(c.Name)
					c.InventoryItem:Destory()
				end
			end
			end
	end
end
-- NewTool Added
local Childd
game.Players.LocalPlayer.Backpack.ChildAdded:Connect(function(Child)
	if Child ~= Childd and #Tools < 11 then
		table.insert(Tools,#Tools+1,Child)
		Num =Num + 1
	end
	updatehotbar()
end)

-- Tool Removed
game.Players.LocalPlayer.Backpack.ChildRemoved:Connect(function(Child)
			if Child.Parent ~= game.Players.LocalPlayer.Character then
				table.remove(Tools,Tools[Child])
				Num =Num - 1
				messdisplayed = false
			else
				Childd = Child
			end
	updatehotbar()
end)

-- When Tool Is Picked
game.Players.LocalPlayer.Character.ChildAdded:Connect(function(Child)
	if Child ~= Childd then
		game.ReplicatedStorage.UnEquipTools:FireServer()
	end
end)

local equipped = false
local db = false
-- Unequip / Equip
game:GetService("UserInputService").InputBegan:Connect(function(In)
	for i,v in pairs(Tools) do
		if In.KeyCode == Enum.KeyCode[NumToWords[i]] and v.Parent == game.Players.LocalPlayer.Backpack or v.Parent == game.Players.LocalPlayer.Character then
			if not db then
				db = true
				if not equipped then
					equipped = true
					game.ReplicatedStorage.EquipTools:FireServer(v)
					for _,Label in pairs(script.Parent.Frame:GetChildren()) do
						if Label.Name == v.Name then
							EquippedItem = Label.Stroke
							EquippedItem.Thickness = 5
						end
					end
					wait(0.1)
					for _,Label in pairs(script.Parent.Frame:GetChildren()) do
						if Label.Name == v.Name then
							EquippedItem = Label.Stroke
							EquippedItem.Thickness = 5
						end
					end
				else
					if In.KeyCode == Enum.KeyCode[NumToWords[i]]  then
						EquippedItem.Thickness = 0
						game.ReplicatedStorage.UnEquipTools:FireServer()
						equipped = false
					end
				end
				wait(0.2)
				db = false
			end
		end		
	end
end)
-- Restrictions
game:GetService("RunService").Heartbeat:Connect(function()
	if Restrict == 1 then
		Restrict = 0
		local ResClone = script.Parent.Restrict:Clone()
		ResClone.Parent = script.Parent
		local TS = game:GetService("TweenService")
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
		local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
		local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
		ResClone.TextTransparency = 0
		ResClone.UIStroke.Transparency = 0
		ResClone.Text = "HotBar Filled!"
		ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),"Out","Sine",2)
		wait(0.2)
		Tween1:Play()
		Tween2:Play()
		wait(2)
		ResClone:Destroy()
	elseif Restrict == 2 then
		Restrict = 0
		local ResClone = script.Parent.Restrict:Clone()
		ResClone.Parent = script.Parent
		local TS = game:GetService("TweenService")
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
		local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
		local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
		ResClone.TextTransparency = 0
		ResClone.UIStroke.Transparency = 0
		ResClone.Text = "Inventory Filled!"
		ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),"Out","Sine",2)
		wait(0.2)
		Tween1:Play()
		Tween2:Play()
		wait(2)
		ResClone:Destroy()
	elseif Restrict == 3 then
		Restrict = 0
		local ResClone = script.Parent.Restrict:Clone()
		ResClone.Parent = script.Parent
		local TS = game:GetService("TweenService")
		local Info = TweenInfo.new(2,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,0,false,0)
		local Tween1 = TS:Create(ResClone,Info,{TextTransparency = 1})
		local Tween2 = TS:Create(ResClone.UIStroke,Info,{Transparency = 1})
		ResClone.TextTransparency = 0
		ResClone.UIStroke.Transparency = 0
		ResClone.Text = "Inventory Is Full!"
		ResClone:TweenPosition(UDim2.new(0.3, 0,0.18, 0),"Out","Sine",2)
		wait(0.2)
		Tween1:Play()
		Tween2:Play()
		wait(2)
		ResClone:Destroy()
	end
	local timeout = false
	for i,v in pairs(script.Parent:GetDescendants()) do
		if v:FindFirstChild("IsItem") and v.Parent ~= script then
			v.MouseButton1Click:Connect(function()
				script.Parent.Change.Visible = true
				script.Parent.Change.Title.Text = "Change "..v.Name
				script.Parent.Change.Cancel.MouseButton1Click:Connect(function()
					script.Parent.Change.Visible = false
				end)
				script.Parent.Change.Confirm.MouseButton1Click:Connect(function()
					if not timeout then
						timeout = true
						local Slot = script.Parent.Change.Input.Text
						if #Slot == 0 then return end
						if v.Parent == script.Parent.Inventory.StoreArea then

						else					
							local object = table.find(Tools,game.Players.LocalPlayer.Backpack[v.Name])
							local Obj = Inventory[Slot]
							table.remove(Tools,table.find(Tools,game.Players.LocalPlayer.Backpack[v.Name]))
							table.insert(Inventory,Slot,object)
							if Obj then
								table.remove(Tools,Slot)
								table.insert(Inventory,#Inventory,Obj)
							end
							updatehotbar()
						end
						wait(0.5)
						timeout = false
					end
				end)
			end)
		end
	end
end)

Please give us more info. What the GUI looks like in Explorer, the errors, screenshots. I recommend using the starter questions when making a post in this category.

i just also added a model link you can use it