My inventory equip script is broken and I dont know how to fix it

Client Side

local ReplicatedStorage = game.ReplicatedStorage
local template = script.Template
local weaponTemplate = script.WeaponTemplate
local loadInventoryEvent = ReplicatedStorage.RemoteEvents.LoadInventory
local player = game.Players.LocalPlayer
local infoFrame = script.Parent.Parent.InfoFrame
local ArmorinfoFrame = script.Parent.Parent.ArmorInfoFrame

game.Players.PlayerAdded:Connect(function(plr)
plr:WaitForChild(“Backpack”):ClearAllChildren()
end)

loadInventoryEvent.OnClientEvent:Connect(function(args)
for index, Instance1 in pairs(script.Parent:GetChildren()) do
if Instance1:IsA(“ScrollingFrame”) then
for index, Instance2 in pairs(Instance1:GetChildren()) do
if Instance2:IsA(“Frame”) or Instance2:IsA(“TextButton”) then
Instance2:Destroy()
end
end
end
end
for itemCount, itemName in pairs(args:GetChildren()) do
if itemName:IsA(“Tool”) then
local itemType = “Weapon”
local Index = require(ReplicatedStorage.ItemInfoIndex)
local itemNameName = itemName.Name
local button = weaponTemplate:Clone()
button.Name = itemName.Name
button.Visible = true
button.Parent = script.Parent.WeaponInventory
button.Text = itemName.Name
button.MouseButton1Click:Connect(function()
ArmorinfoFrame.Visible = false
infoFrame.Visible = true
infoFrame.ItemName.Text = itemName.Name
infoFrame.Stats.Damage.Text = Index[itemNameName].MinDamage…“~”…Index[itemName.Name].MaxDamage
infoFrame.Stats.CritDamage.Text = Index[itemNameName].CritDamage
infoFrame.Stats.CritChance.Text = Index[itemNameName].CritChance…“%”
infoFrame.Stats.MissChance.Text = Index[itemNameName].MissChance…“%”
infoFrame.Stats.ArmorPierce.Text = Index[itemNameName].ArmorPierce
infoFrame.Equip.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvents.Equip:FireServer(itemNameName, itemType)
end)
end)
elseif itemName:IsA(“Part”) then
local itemNameName = itemName.Name
local button = template:Clone()
button.Name = itemName.Name
button.Visible = true
button.Parent = script.Parent.MaterialInventory
button.ItemName.Text = itemName.Name

	elseif itemName:IsA("Model") then
		local itemType = "Armor"
		local Index = require(ReplicatedStorage.ItemInfoIndex)
		local itemNameName = itemName.Name
		local button = weaponTemplate:Clone()
		button.Name = itemName.Name
		button.Visible = true
		button.Parent = script.Parent.ArmorInventory
		button.Text = itemName.Name
		button.MouseButton1Click:Connect(function()
			ArmorinfoFrame.Visible = true
			infoFrame.Visible = false
			ArmorinfoFrame.ItemName.Text = itemName.Name
			ArmorinfoFrame.Stats.Damage.Text = Index[itemNameName].Damage
			ArmorinfoFrame.Buff.Text = Index[itemNameName].Buff
			ArmorinfoFrame.Stats.Protection.Text = Index[itemNameName].Protection
			ArmorinfoFrame.Stats.Mana.Text = Index[itemNameName].Mana
			ArmorinfoFrame.Equip.MouseButton1Click:Connect(function()
				game.ReplicatedStorage.RemoteEvents.Equip:FireServer(itemNameName, itemType)
			end)
		end)
	end
end

end)

Server Side

local ReplicatedStorage = game.ReplicatedStorage
local Index = require(ReplicatedStorage.ItemInfoIndex)

game.Players.PlayerAdded:Connect(function(plr)
local InventoryFolder = Instance.new(“Folder”)
InventoryFolder.Name = plr.UserId
InventoryFolder.Parent = game.ReplicatedStorage.PlayerData

local ItemHolder = Instance.new("Folder")
ItemHolder.Name = "ItemHolder"
ItemHolder.Parent = InventoryFolder

plr.CharacterAdded:Connect(function()
	local Protection = Instance.new("IntValue")
	Protection.Name = "Protection"
	Protection.Parent = plr.Character
	Protection.Value = 0
	
	local Damage = Instance.new("IntValue")
	Damage.Name = "Damage"
	Damage.Parent = plr.Character
	Damage.Value = 0
end)

local function LoadInventory(Inv)
	game.ReplicatedStorage.RemoteEvents.LoadInventory:FireClient(plr, Inv)
end

local function loadItemsData(player, TableArg)
	print(TableArg)
	local count = 0
	for i=1, #TableArg do
		count = count + 1
		local weapon = game.ReplicatedStorage.Items:FindFirstChild(TableArg[count]):Clone()
		weapon.Parent = game.ReplicatedStorage.PlayerData:FindFirstChild(player.UserId).ItemHolder
	end
end

local data = game:GetService("DataStoreService"):GetDataStore("DataStore"..plr.UserId)
local testdata = data:GetAsync("ITEMDATA")
if testdata then
	loadItemsData(plr ,testdata)
	LoadInventory(ItemHolder)
else
	wait(1)
end

ItemHolder.ChildAdded:Connect(function()
	LoadInventory(ItemHolder)
end)

ItemHolder.ChildRemoved:Connect(function()
	LoadInventory(ItemHolder)
end)

local Humanoid = plr.Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
	task.wait(1.5)
	LoadInventory(ItemHolder)
end)

ReplicatedStorage.RemoteEvents.ItemDrop.Event:Connect(function(itemName)
	if ReplicatedStorage.Items:FindFirstChild(itemName) then
		if ItemHolder:FindFirstChild(itemName) then
			wait()
		else
			local item = ReplicatedStorage.Items:FindFirstChild(itemName)
			item.Parent = ItemHolder
			LoadInventory(ItemHolder)
		end
	end
end)

end)

game.ReplicatedStorage.RemoteEvents.Equip.OnServerEvent:Connect(function(plr, arg, itemType)
if itemType == “Weapon” then
local currentWeapon = plr.Character:FindFirstChild(arg) or plr.Backpack:FindFirstChild(arg)
if currentWeapon then
currentWeapon:Destroy()
plr.Character:FindFirstChild(currentWeapon):Destroy()
else
plr.Backpack:ClearAllChildren()
local clone = game.ReplicatedStorage.Items:FindFirstChild(arg):Clone()
clone.Parent = plr.Backpack
end
elseif itemType == “Armor” then
local currentArmor = plr.Character:FindFirstChild(arg)
if currentArmor then
plr.Character.Humanoid.MaxHealth = 100
plr.Character.Damage.Value = 0
plr.Character:FindFirstChild(“Protection”).Value = 0
currentArmor:Destroy()
else
local clone = game.ReplicatedStorage.Items:FindFirstChild(arg):Clone()
clone.Parent = plr.Character
local cloneChildren = clone:GetChildren()
plr.Character:FindFirstChild(“Damage”).Value = plr.Character:FindFirstChild(“Damage”).Value + Index[arg].Damage
plr.Character:FindFirstChild(“Protection”).Value = plr.Character:FindFirstChild(“Protection”).Value + Index[arg].Protection
plr.Character.Humanoid.MaxHealth = plr.Character.Humanoid.MaxHealth + plr.Character:FindFirstChild(“Protection”).Value
for i=1, #cloneChildren do
cloneChildren[i].CFrame = plr.Character:FindFirstChild(clone:GetChildren()[i].Name).CFrame
local motor6d = cloneChildren[i]:FindFirstChild(“WeldConstraint”)
motor6d.Part1 = plr.Character:FindFirstChild(cloneChildren[i].Name)
end
end
end
end)

game.Players.PlayerRemoving:Connect(function(Player)
game.ReplicatedStorage.RemoteEvents.Saving:Fire(Player,true)
end)

game.ReplicatedStorage.RemoteEvents.Saving.Event:Connect(function(player,Leaving)
local function LoadInventory(Inv)
game.ReplicatedStorage.RemoteEvents.LoadInventory:FireClient(player, Inv)
end
local data = game:GetService(“DataStoreService”):GetDataStore(“DataStore”…player.UserId)
local ITEMDATA = {}
local tool = game.ReplicatedStorage:WaitForChild(“PlayerData”):FindFirstChild(player.UserId).ItemHolder:GetChildren()
local count = 0
for i=1,#tool do
count = count + 1
table.insert(ITEMDATA,count,tool[i].Name)
end
data:SetAsync(“ITEMDATA”,ITEMDATA)
print(ITEMDATA)
game.ReplicatedStorage:WaitForChild(“PlayerData”):FindFirstChild(player.UserId):Destroy()
end)

The equip system is weird and broken, ive been looking around the dev forum and asking people in different communities, it had been a month and i cant fix it