What is DataStore? Also how to implement it in my games?

  • I have been thinking how can I implement it in my games, I have been looking forward in saving things. Also how to use it in different ways.

  • I want a simple breakdown and services I can use to make this happen, also other functions and events to use. :grinning:

  • I haven’t seen a way I could know, also I have tried learning but it’s a little confusing for me.

1 Like

There’s tons of tutorials you could’ve searched on the internet…

When you are familiar with the functions of DataStoreService, you can look on other public modules which specialise in data storing. Take a look at these modules.

DataStore or DataStoreService allows you to store values under special “keys”.
For example, whenever some player joins, you check if you have his userid as a datastore key, for example:

local DSS = game:GetService('DataStoreService') -- Init datastore service
local DS = DSS:GetDataStore('PlayerData') -- Get all the data of PlayerData DataStore

game:GetService('Players').PlayerAdded:Connect(function(plr) -- Create an event
    local data = nil
    local succ = false
    local timeout = 0
    while succ == false and timeout <= 10 do -- Repeat until no errors or attempted 10 times
        local success, err = pcall(function()
            data = DS:GetAsync(plr.UserId)
        end
        task.wait(1)
        succ = success
        timeout += 1
    end
    if data then
        -- Use variables stored under player DataStore
    end
end)

Similar way to store data, you simply use DS:SetAsync(plr.UserId, <data>), where data can be anything such as string, int, table, array.

was there an error or the data:GetAsync(plr.UserId) intentional?

My bad, fixed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.