How to save every players key who has joined your game in a table

Can anyone help because my game wouldve been released if i found a fix to the problem

5 Likes

Are you trying to store a list of every player that ever joined your game?
You could use a datastore for each player that has a bool set to false by default, when the player joins, this player is added to a second datastore(a datastore which holds a string containing all the saved players), unless the bool is true.
the player specific datastore with the bool value is then marked as true so the player only gets added to the list once.

5 Likes

Firebase datastore i guess pppppp

3 Likes

I’d say probably use the DataStoreService.

You can’t get them all from a normal DataStore. You would need to use an OrderedDataStore’s GetSortedAsync() function.

local store = game:GetService("DataStoreService"):GetOrderedDataStore("YourStore")
local players = game:GetService("Players")

--save the player's key to the store when they leave
local function onLeave(player:Player)
    local success, err = pcall(function()
        store:SetAsync("Key_"..player.UserId, 1)
    end)
end
players.PlayerRemoving:Connect(onLeave)

--get all the keys
local function getAllKeys()
    local keys
    local success, err = pcall(function()
        local keys = store:GetSortedAsync(false, --[[number of keys to be read]])
    end)
    if success and keys then
        local page = keys:GetCurrentPage()
        for i, saveData in ipairs(page) do
            local rawKey = page[i]
            local key = rawKey.key
            local user = string.split(key, "_")[2]
            local success, err = pcall(function()
                print(players:GetNameByUserIdAsync(user))
            end)
        end
    end
end

edit: Apparently you can get all the keys from a normal DataStore using ListKeysAsync().

4 Likes

Every datastoreservice is better than roblox datastore XD

1 Like

But personally I would use httpservice to send the userid of every player that joined to a google spreadsheet.
This way I can configure the spreadsheet itself to delete any duplicates.
Additionally you could add another script to the spreadsheet that fetches player names and account links from the given userid.

2 Likes

At least it’s provided to us for free :grinning:

Like if you tried to make a website with an account system you’d have to pay for a database which kinda sucks (this was me)

2 Likes

Or host it yourself on an old secondhand laptop for 20$

2 Likes

Xd. Firebase is cool because it’s for free and easy to use. You’re right but if you want to make bigger game, i prefere dss with more storage :wink:

1 Like

ehhhhhhh energy bills in my city are going up :arrow_up:

I’ve heard firebase is free but you need to add a bank account or CC info

2 Likes

Idk, i don’t have to. It’s your opinion, so yeah. Have a nice day

2 Likes

Weld one of these badboys to the back of the laptop.

Amazon solar panel

2 Likes

You too

Jeez that’s a long link lmao but uhh it’s probably more worth it and more reliable to use DSS imo

thanks for telling us about this though

2 Likes

DataStore:ListKeysAsync() is your best bet here - it lists out all the existing keys of that given datastore you’re trying to get all the keys from.
If this didn’t help you, you’ll have to elaborate on your question further.

1 Like

Also, sorry to have to add this on as a separate reply to the thread, I don’t want to have to mention the OP for something irrelevant -

-but it’s pretty silly to still see people say things like “x database is better than roblox datastores”.

Firebase is cool because it’s for free and easy to use.

It’s free - until you start to scale it up. Afterwards, the cost also scales up, often to the point where it’s unsustainable for the average Roblox developer.

Or host it yourself on an old secondhand laptop for 20$

Right… let’s conveniently forget that energy and internet bills exist, for the sake of argument.

It’s sh*t like this that tells me (and many others) that the people who says things like these haven’t actually done anything decently sized on Roblox yet.
Puts into question just how versed they are in this topic.

The grass isn’t always greener on the other side - you just haven’t been there yet.
Besides, this is scripting-support. Keep this nonsense elsewhere.

It was a joke, sorry you couldn’t tell.
I thought it was obvious considering my advice to weld a solar panel to the back of it.

A Google Sheet can only contain I think it’s 15k rows, that can go in a few months for most games that have a DAU of like 50 or more.

2 Likes

Besides, this is scripting-support. Keep this nonsense elsewhere.