I have a child added script and it works so I don't understand why this one isn't working. it remove it from the table, but when I re join the game, the friend name is still there. so it moved it, but didn't save. anybody know why it doesn't save?
game.Players:FindFirstChild(plr.Name).Backpack.Friends.ChildRemoved:Connect(function() DS:UpdateAsync("43214235235", function(old) friends[plr.UserId] = old local removed = plr.Backpack.RemovedFriend -- player's ID table.remove(friends[plr.UserId], removed.Value) removed:Destroy() return friends[plr.UserId]; end) end)
You are using table.remove() incorrectly.
The second parameter is the position of the value in the table.
For example,
local test_table = {'hello','goodbye'} -- Forming the table print(table.concat(test_table,', ')) -- hello, goodbye table.remove(test_table,2) -- Removing second value of table print(table.concat(test_table,', ')) -- hello
A way to find the position in the table is to make a function for that purpose, such as:
function findPosition(tab,val) for i,v in pairs(tab) do -- loop through table if v == val -- if the value is what we're looking for return i -- return the position in the table end end return nil -- return nil if it doesn't exist end
and then:
table.remove(my_table,findPosition(my_table,my_value))