I'm trying to adapt a script from Roblox Wiki for Saving Player data.Can someone help? [closed]
Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
This is a part of a script on Roblox wiki, Saving Player Data. I've tried altering it in all sorts of ways but i just can't figure anything out. I've made an obby and a leaderboard that tracks 2 things.The level you've reached and a number of trophies you've collected, and that's the information that's i need saved when a player leaves(i also need it to teleport the player to a checkpoint of a level,based on this info, but i'd be happy with just getting it to remember the numbers) Most of the script is already done i just don't understand what variables i need to add to make it work for my game.
Thanks for your time
02 | local PlayerStatManager = { } |
05 | local DataStoreService = game:GetService( 'DataStoreService' ) |
06 | local playerData = DataStoreService:GetDataStore( 'Mobbystats' ) |
14 | function PlayerStatManager:ChangeStat(player, statName, changeValue) |
15 | sessionData [ player ] [ statName ] = sessionData [ player ] [ statName ] + changeValue |
20 | local function dataStoreRetry(dataStoreFunction) |
26 | success = pcall ( function () data = dataStoreFunction() end ) |
27 | if not success then wait( 1 ) end |
28 | until tries = = DATASTORE_RETRIES or success |
30 | error ( 'Could not access DataStore! Warn players that their data might not get saved!' ) |
36 | local function getPlayerData(player) |
37 | return dataStoreRetry( function () |
38 | return playerData:GetAsync(player.UserId) |
43 | local function savePlayerData(player) |
44 | if sessionData [ player ] then |
45 | return dataStoreRetry( function () |
46 | return playerData:SetAsync(player.UserId, sessionData [ player ] ) |
54 | local function setupPlayerData(player) |
55 | local success, data = getPlayerData(player) |
58 | sessionData [ player ] = false |
62 | sessionData [ player ] = { Stage = 1 , TrophiesFound = 0 } |
63 | savePlayerData(player) |
66 | sessionData [ player ] = data |