Saltar al contenido
Skillpedia
Programación general6,6 mil · #13837

roblox-datastores

Qué hace

Explica cómo guardar el progreso de los jugadores en Roblox para que se conserve entre sesiones. Es para desarrolladores que quieren que monedas, niveles o objetos persistan.

Cuándo usarla

  • ✓Cuando necesitas guardar monedas, niveles o inventario de jugadores entre sesiones en Roblox.
  • ✓Cuando los jugadores pierden datos o los datos se sobrescriben al salir.
  • ✓Cuando quieres crear una clasificación persistente en Roblox.

Link de la skill

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/other-engines/roblox-datastores/SKILL.md

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/other-engines/roblox-datastores/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Haz que mi juego de Roblox recuerde las monedas de cada jugador después de que salga y vuelva.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

Explica cómo cargar los datos cuando un jugador entra, guardar al salir o cuando el servidor se apaga, envolver cada llamada para gestionar los fallos, y usar reintentos y almacenes ordenados para las clasificaciones.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de GitHub.

Roblox DataStores

Persist data across sessions in Roblox with DataStoreService: loading on join, saving on leave and shutdown, safe updates, retries, and ordered stores for leaderboards. Server-side only.

When to use

  • Use to save/load player progress (coins, inventory, levels), build persistent leaderboards, or fix data loss, overwrites, and throttling.
  • Use when server code calls DataStoreService, GetDataStore, GetAsync, SetAsync, UpdateAsync, or GetOrderedDataStore.

When not to use: general scripting, services, remotes, the client/server split → roblox-luau. High-frequency temporary state (matchmaking, per-round) → memory stores (a different service). Engine-agnostic persistence theory → save-systems.

Core workflow

  1. Enable Studio access once. In a published place, File → Experience Settings → Security → Enable Studio Access to API Services (use a separate test place; Studio hits the same live data as players). DataStores work only from server Scripts, never LocalScripts.
  2. Get a store, then read/write by key. DataStoreService:GetDataStore("Name"); key per player is usually "Player_" .. player.UserId.
  3. Wrap every call in pcall. GetAsync/SetAsync/UpdateAsync are network calls that can fail; an unguarded failure errors the thread and risks data loss.
  4. Load on PlayerAdded, save on PlayerRemoving, and also BindToClose. A leaving player and a shutting-down server both need a final save.
  5. Prefer UpdateAsync for read-modify-write (multi-server safe) over SetAsync (blind overwrite). On a failed load, do not overwrite with defaults — abort the save so you don't wipe good data.
  6. Use OrderedDataStore for ranked data (leaderboards) via GetSortedAsync. Test by joining, changing data, rejoining, and confirming it persisted.

Patterns

1. Load on join (pcall-guarded)

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local store = DataStoreService:GetDataStore("PlayerData")

local DEFAULT = { Coins = 0, Level = 1 }

Players.PlayerAdded:Connect(function(player)
    local key = "Player_" .. player.UserId
    local ok, data = pcall(function()
        return store:GetAsync(key)
    end)

    if not ok then
        -- Load FAILED (network). Do not treat as a new player; flag so we never save
        -- over their real data with defaults.
        warn("Load failed for", player.Name, data)
        player:SetAttribute("DataLoaded", false)
        return
    end

    player:SetAttribute("DataLoaded", true)
    local profile = data or DEFAULT          -- nil == genuinely new player
    applyToLeaderstats(player, profile)
end)

2. Save with UpdateAsync (multi-server safe)

-- UpdateAsync reads the latest value, then writes what the callback returns.
-- The callback MUST NOT yield (no task.wait, no further Async calls inside it), and it
-- can run more than once if another server writes the key first, so keep it pure.
local function savePlayer(player)
    -- Save only after a confirmed load. `~= true` also covers a player who leaves while
    -- GetAsync is still in flight (attribute still nil), which `== false` would miss.
    if player:GetAttribute("DataLoaded") ~= true then return end
    local key = "Player_" .. player.UserId
    local newData = gatherDataFor(player)    -- a plain table of serializable values

    local ok, err = pcall(function()
        store:UpdateAsync(key, function(old)
            -- merge/decide here; return nil to cancel the write
            return newData
        end)
    end)
    if not ok then warn("Save failed for", player.Name, err) end
end

3. Save on leave AND on shutdown

Players.PlayerRemoving:Connect(savePlayer)

-- BindToClose runs when the server shuts down; save everyone still in.
-- The server waits at most 30 seconds for it, so save in parallel and yield until done.
game:BindToClose(function()
    local players = Players:GetPlayers()
    local remaining = #players
    if remaining == 0 then return end
    for _, player in players do
        task.spawn(function()
            savePlayer(player)
            remaining -= 1
        end)
    end
    while remaining > 0 do task.wait() end
end)

4. Retry with backoff (transient failures)

local function withRetry(fn, attempts)
    attempts = attempts or 3
    for i = 1, attempts do
        local ok, result 
Preguntas frecuentes

¿Funcionan los DataStores en scripts locales?

No. La skill indica que los DataStores solo funcionan desde scripts de servidor.

¿Por qué activar el acceso de Studio?

La skill indica activar el acceso de Studio a los servicios de API para que Studio pueda usar los datos reales, y usar un lugar de prueba separado para ello.

¿Sirve para el estado temporal de una partida?

No. El estado temporal usa otro servicio, y esta skill cubre los datos guardados.

Detalles

Descripción original del autor

Persist player data in Roblox with DataStoreService: GetDataStore, GetAsync/ SetAsync/UpdateAsync/IncrementAsync wrapped in pcall, load-on-join and save-on-leave plus BindToClose, retries, and OrderedDataStore leaderboards. Use when saving or loading persistent data in a Roblox experience — when the user mentions DataStore, DataStoreService, GetAsync, SetAsync, UpdateAsync, save player data, or leaderboards. For general Luau scripting use roblox-luau.

repo: gamedev-skills/awesome-gamedev-agent-skills

Popularidad

Estrellas en GitHub
6,6 mil
Posición en el ranking
#13837
Licencia
Apache-2.0
Actualizada
28/10/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas