-
What do you want to achieve? Be able to fetch 10 users that have a boolean saved with a true value.
-
What is the issue? I simply cannot find a way since you cant sort booleans
-
What solutions have you tried so far? The dev hub doesnt seem to contain any info about this either
This is for a ban land GUI where it should just show 10 users that are banned.
But i can’t seem to find anything related to fetching that exact thing, so does any one else know?
How are you saving your data? If you have it saved per user id, then you wouldn’t really be able to go about finding the users without checking EVERY user id. If you have the data saved in a table however you would be able to sort that and check if it’s true or false.
1 Like
So its saved like this
Data {
UserId: {
Boolean: Value
},
UserId: {
Boolean: Value
}
}
SO. I got it. The code is bad and there’s probably a better / more efficient way to do it. But it gets the job done.
Code
table.sort(data, function(a, b)
local aVal = a.Banned == true and 1 or 0;
local bVal = b.Banned == true and 1 or 0;
return aVal > bVal;
end);
Original
Sorted
1 Like
Finne just ask this because i’m brain dead at 2 in the morning
but how would i empty that database into an array like state
or just sort the whole thing it self
also made a slight mistake on how it saves but i know how to fix that myself
This is how its saved:
local datastore = {
'UserId', {
["Muted"] = false;
["Banned"] = true;
["BanReason"] = 'None';
["MuteReason"] = 'None';
["BanMod"] = 'SomeUser';
["MuteMod"] = 'None';
},
'UserId', {
["Muted"] = false;
["Banned"] = true;
["BanReason"] = 'None';
["MuteReason"] = 'None';
["BanMod"] = 'SomeUser';
["MuteMod"] = 'None';
},
'UserId', {
["Muted"] = false;
["Banned"] = true;
["BanReason"] = 'None';
["MuteReason"] = 'None';
["BanMod"] = 'SomeUser';
["MuteMod"] = 'None';
}
}
When you say datastore = {} do you mean that all the data is stored in one table, or you have keys as the UserId?
--saved like this?
datastore:SetAsync("Key", dataOfAllPlayers)
--or this?
datastore:SetAsync(player.UserId, data)
If it’s the second, there used to not be a way to get this. But looking on the wiki they added a function to DataStores called “ListKeysAsync()”
This would be what you’re looking for to find the keys for everyone that’s played, but then you still sadly have to grab all the data individually…
1 Like
The second one as in
as in much anger yes
datastore:SetAsync(player.UserId, data)