Help On Lootbox UI

I am making a system where players can find these box around the map and there is a ui similar to ui you see in battle royale games, that you can add things to your inventory and remove. My problem is that whenever a player put a skill back into the box, the ui don’t do anything. My code is below :

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local lootselection = script.Parent.LootSelection:Clone()
    lootselection.Parent = player.PlayerGui
    for i,v in pairs(script.Parent:WaitForChild("Loots"):GetChildren()) do
        if v:IsA("LocalScript") then
            local slot = lootselection.LootScroll.Template:Clone()
            slot.Name = v.Name
            slot.Parent = lootselection.LootScroll
            slot.Visible = true
            print("Successfully Added A Slot")
            slot.MagicTypeImage.Image = game.ReplicatedStorage.SkillFolder[v.Name].ImageId.Value
            slot.LootName.Text = v.Name
            slot.LootType.Text = v.LootType.Value
            slot.ViewFrame.Desc.Text = game.ReplicatedStorage.SkillFolder[v.Name].Desc.Value
            slot.ViewFrame.ManaCost.Text = game.ReplicatedStorage.SkillFolder[v.Name].ManaCost.Value
            slot.View.MouseEnter:Connect(function()
                slot.ViewFrame.Visible = true
            end)
            slot.View.MouseLeave:Connect(function()
                slot.ViewFrame.Visible = false
            end)
            slot.View.MouseButton1Click:Connect(function()
                v.Parent = player.Backpack.SkillFolder
                slot:Destroy()
            end)
            lootselection.Close.MouseButton1Click:Connect(function()
                lootselection:Destroy()
                return
            end)
        end
    end
    script.Parent.Loots.ChildAdded:Connect(function(instance)
        print("A child is added")
        if instance:IsA("LocalScript") then
            local slot = lootselection.LootScroll.Template:Clone()
            slot.Name = instance.Name
            slot.Parent = lootselection.LootScroll
            slot.Visible = true
            print("Successfully Added A Slot")
            slot.MagicTypeImage.Image = game.ReplicatedStorage.SkillFolder[instance.Name].ImageId.Value
            slot.LootName.Text = instance.Name
            slot.LootType.Text = instance.LootType.Value
            slot.ViewFrame.Desc.Text = game.ReplicatedStorage.SkillFolder[instance.Name].Desc.Value
            slot.ViewFrame.ManaCost.Text = game.ReplicatedStorage.SkillFolder[instance.Name].ManaCost.Value
            slot.View.MouseEnter:Connect(function()
                slot.ViewFrame.Visible = true
            end)
            slot.View.MouseLeave:Connect(function()
                slot.ViewFrame.Visible = false
            end)
            slot.View.MouseButton1Click:Connect(function()
                instance.Parent = player.Backpack.SkillFolder
                slot:Destroy()
            end)
            lootselection.Close.MouseButton1Click:Connect(function()
                lootselection:Destroy()
                return
            end)
        end
    end)
end)

Never mind, I found the problem.