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?
01 | game.Players:FindFirstChild(plr.Name).Backpack.Friends.ChildRemoved:Connect( function () |
02 |
03 | DS:UpdateAsync( "43214235235" , function (old) |
04 | friends [ plr.UserId ] = old |
05 | local removed = plr.Backpack.RemovedFriend -- player's ID |
06 | table.remove(friends [ plr.UserId ] , removed.Value) |
07 | removed:Destroy() |
08 | return friends [ plr.UserId ] ; |
09 | end ) |
10 | end ) |
You are using table.remove() incorrectly.
The second parameter is the position of the value in the table.
For example,
1 | local test_table = { 'hello' , 'goodbye' } -- Forming the table |
2 | print (table.concat(test_table, ', ' )) -- hello, goodbye |
3 | table.remove(test_table, 2 ) -- Removing second value of table |
4 | 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:
1 | function findPosition(tab,val) |
2 | for i,v in pairs (tab) do -- loop through table |
3 | if v = = val -- if the value is what we're looking for |
4 | return i -- return the position in the table |
5 | end |
6 | end |
7 | return nil -- return nil if it doesn't exist |
8 | end |
and then:
1 | table.remove(my_table,findPosition(my_table,my_value)) |