Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make leaderboard stats save between places in a universe?

So I'm making an adventure game and I want Coins and Crystals to save between places (worlds) in the game (universe) but I'm literally stumped and I can't come up with anything at all so I'd really appreciate if someone could help me out here.

1 comment

2

DataStores. Unlike Data Persistence, DataStores can save information place to place so long as the places are in a single universe/game.

1 answer

DataStores

DataStores allow you to save data across all places in a game. It can only save primitive datatypes and some tables, so complex data will need to be serialized.

How do I save?

You can use DataStore.SetAsync

local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore();
-- Assumes Player to be predefined
DataStore:SetAsync(Player.userId..'Coins', Player.leaderstats.Coins.Value);
DataStore:SetAsync(Player.userId..'Crystals', Player.leaderstats.Crystals.Value);

How do I load?

You can use DataStore.GetAsync

local DataStore = game:GetService("DataStoreService"):GetGlobalDataStore();
-- Assumes Player to be predefined
Player.leaderstats.Coins.Value = DataStore:GetAsync(Player.userId..'Coins')
Player.leaderstats.Crystals.Value = DataStore:GetAsync(Player.userId..'Crystals');

Any questions? Ask.

This discussion is preserved as it was. New answers, comments, and votes are closed.