#Table remove not working

5 messages · Page 1 of 1 (latest)

rose trail
#

When I click on a frame I am marking the item in the table in the server
when I click on confirm i should remove all the item i marked from the table
if i select 1 frame and click on confirm it works
if i select 2 or more frames and click on confirm it only removes the last one i selected

client (click frame)

ItemFrame.ItemButton.MouseButton1Click:Connect(function()
    if script.Parent.Visible == true then
        if ItemFrame.SelectedForSell.Value == false then
            ItemFrame.SelectedForSell.Value = true
            MarkItemToSellRemote:FireServer(itemData, true)
        else
            ItemFrame.SelectedForSell.Value = false
            MarkItemToSellRemote:FireServer(itemData, false)
        end
    end
end)

server (when client click frame)

ReplicatedStorage.SellSystem.MarkItemToSell.OnServerEvent:Connect(function(player, itemData, markToSell)
    local profile = Manager.Profiles[player]
    if not profile then return end
    
    for _, item in profile.Data.Inventory do
        if item.ID == itemData.ID then
            print(profile.Data.Inventory[_].ID)
            profile.Data.Inventory[_].SelectToSell = markToSell
        end
    end
end)
#

client (confirm button)

local SellItemsRemote = game:WaitForChild("ReplicatedStorage"):WaitForChild("SellSystem").SellItems

script.Parent.MouseButton1Click:Connect(function()
    SellItemsRemote:FireServer()
end)

server (when client click confirm button

ReplicatedStorage.SellSystem.SellItems.OnServerEvent:Connect(function(player)
    local profile = Manager.Profiles[player]
    if not profile then return end
    
    for i, item in profile.Data.Inventory do
        if item.SelectToSell then
            print("sell")
            print(profile.Data.Inventory[i].ID)
            table.remove(profile.Data.Inventory, i)
        end
    end
    
    ShowItems(player, profile.Data.Inventory)
end)
#

select one and delete one

#

select two and delete one