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

How do you remove a key/value pair from a dictionary?

Say I have this dictionary:

local list = {key1 = 506, key2 = 1567, key3 = 9015}

How could I remove a key from this dictionary without just setting the value to nil? The problem is that I'm trying to remove a key/value pair from an Ordered Data Store, so the value cannot become nil.

Any and all help is appreciated. Thanks!

1 answer

✓ Accepted answer

You cannot assign nil to a datastore key, but if you're getting a dictionary from a datastore key, you can assign nil to its values.

You mention OrderedDataStores. The only solution in this case is to assign the lowest possible value to the key (so that it will be sorted last). ex, you might store -math.huge, and then ignore those values if you find them later. (Disclaimer: I haven't tried storing -math.huge, but if that doesn't work, just chose a value that should never show up normally. -1 would suffice if you're only going to be storing values that are 0 or greater.)

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