I apologize if my question didn't make enough sense, I'm kind of still learning.
local UserItems = {
['Banana'] = 20429;
['Apple'] = 50000;
['Watermelon'] = 250000;
['Pineapple'] = 30000;
}
Let's say that a user has these items above, how do I iterate through the dictionary and get the items that costs, let's say, 300K? (In that case, it should pick the Apple and Watermelon to make up the 300K)

6 comments
Are you trying to find the elements which, when summed together equal to 250 thousand? Or the single element that costs 250 thousand?
Yes exactly, when summed up together they equal 250,000.
And 250,000 is not constant, it's just an example, I want it to get the suitable items that sum up to a certain number, like if my input is 330,000 it should pick watermelon, apple, and pineapple. Also sorry for my misleading question i should've said 300K not 250K.
Fixed my question.
This is a pretty tough question, since there isn't a built-in method to do exactly what you're asking for and mostly likely requires making an alogrithm of your own. I'll try spending some time on this question and if I can, I'll give you an answer
Your help in this matter is really appreciated, thank you so much.