Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

(friends folder) child removed from folder, removed from table, but doesn't save. Why?

Asked by 7 years ago

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)    

1 answer

Log in to vote
1
Answered by
DevNetx 250 Moderation Voter
7 years ago

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))
0
that works. even though i still had to tweak it for my script. but thanks anyways :D RobloxianDestory 262 — 7y
Ad

Answer this question