Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to create saving slots?

Asked by 1 year ago

I want to add savings slots to my game, but I don't know how I know that I need to use DataStore but... Is there any way to have saving slots

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

Brief explanation.

You could prefix the data store keys with 'slot1_' followed by the user ID of the player.

Don't understand DataStores?

To create saving slots in a Roblox DataStore, you can use the SetAsync method of the DataStoreService class. Here's an example of how you might use it:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("MyDataStore")

local function saveData(player, data)
    local playerKey = tostring(player.UserId)
    myDataStore:SetAsync(playerKey, data)
end

local function loadData(player)
    local playerKey = tostring(player.UserId)
    local success, data = pcall(myDataStore.GetAsync, myDataStore, playerKey)
    if success then
        return data
    end
end
0
Oh ok thanks! Hgamerpro50 0 — 1y
0
Glad I could help. Could you please mark this as an answer to help others who may have the same question? pingsockv2 40 — 1y
0
How do you do the big letters? T3_MasterGamer 2189 — 1y
0
umm you didn't use "local success, data" correctly T3_MasterGamer 2189 — 1y
0
it should be "local success, data = pcall(myDataStore.GetAsync, myDataStore, playerKey)" T3_MasterGamer 2189 — 1y
Ad

Answer this question