Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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))

1 comment

0

that works. even though i still had to tweak it for my script. but thanks anyways :D

This discussion is preserved as it was. New answers, comments, and votes are closed.