Cant seem to fix inventory system

I have been TRYING to fix this inventory system for almost a week straight. I am literally stuck on this on my game. I’m really disappointed in myself for not being able to fix this. Basically I followed DeadGambit’s youtube tutorial but his tutorial’s unequipping script deletes every item in the player’s backpack that has the same name as the item supposed to be deleted/unequipped, For example I have a sword and I equipped it but i already have a sword in my backpack, so there’ll be 2 swords in my backpack, I unequip the sword I just equipped then both swords will get deleted. That’s why I modified the script a bit to make it so an ObjectValue from the gui button for the item will have it’s value as the item in the player backpack. idk if it’s good explaination but please I really REALLY need help with this, I’m really upset.

If you see the tutorial he has a handler script and yes I made that.
local plr = game:GetService("Players").LocalPlayer or game.Players.PlayerAdded:Wait()

local main = script.Parent.Parent.Parent.InventoryFrame
local replicated = game:GetService("ReplicatedStorage")
local remotes = replicated.RemoteEvents
local inventoryremotes = remotes.Inventory

local cooldown = false

for index, child in pairs(script.Parent:GetChildren()) do
	if child:IsA("TextButton") then
		child.MouseButton1Click:Connect(function()
			if child.Name == "Equip" then
				if child.Text == "Equip" then
					for index, items in pairs(main:GetChildren()) do
						if items:IsA("ImageButton") and cooldown == false then
							if script.Parent.ItemDisplayed.Value == items and items.Equipped.Value == false then
								for index, value in pairs(items:GetChildren()) do
									if value:IsA("ObjectValue") and value.Name == "Tool" then
										items.Equipped.Value = true
										inventoryremotes.EquipItem:FireServer(items.name, value.Value, "Equipped")
										print("Activated Remote 1")
										child.Text = "Unequip"
										cooldown = true
										wait(1)
										cooldown = false
									end
								end
							end
						end
					end
				elseif child.Text == "Unequip" then
					for index, items in pairs(main:GetChildren()) do
						if items:IsA("ImageButton") and cooldown == false then
							if script.Parent.ItemDisplayed.Value == items and items.Equipped.Value == true then
								for index, value in pairs(items:GetChildren()) do
									if value:IsA("ObjectValue") and value.Name == "Tool" then
										items.Equipped.Value = false
										inventoryremotes.EquipItem:FireServer(items.name, value.Value, "Unequipped")
										print("Activated Remote 2")
										child.Text = "Equip"
										cooldown = true
										wait(1)
										cooldown = false
									end
								end
							end
						end
					end
				end
			end
		end)
	end
end

I have ALSO made the remotes script he made in the tutorial.
local plr = game:GetService("Players").LocalPlayer or game.Players.PlayerAdded:Wait()

local replicated = game:GetService("ReplicatedStorage")
local remotes = replicated.RemoteEvents
local inventoryremotes = remotes.Inventory
local backpack = plr

inventoryremotes.EquipItem.OnServerEvent:Connect(function(plr, item, object, condition)
	if condition == "Equipped" then
		local selecteditem = replicated.Fruits.Fruit[item]:Clone()
		selecteditem.Parent = plr.Backpack
		object = selecteditem
		print("equipped Item")
	elseif condition == "Unequipped" then
		for index, equippedItems in pairs(plr.Backpack:GetChildren()) do
			if equippedItems.Name == item then
				if object == equippedItems then
					local deleteitem = plr.Backpack[item]
					deleteitem:Destroy()
					object = nil
				end
			end
			print("Destroyed Item")
		end
	end
end)

I have made sure that all objects exist, nothing is missing, just the scripts acting funny when they’re not. Also if you’ve noticed and watched the tutorial, I modified it a little xD. Please help me I would seriously appreciate it. Thank you!