How Can I print out a players Data Using Data Store?
So currently I am playing with DataStores, but I have a difficult time trying to see the values through the console. The closest I got was a table, the furthest I got was a function past that table.
I am using a modulo script with a player on added event on another script.
Anyways, the goal is to print all the data inside my modulo code on the console.
http://wiki.roblox.com/index.php?title=Saving_Player_Data
this is the modulo script I am using
02 | local PlayerStatManager = { } |
05 | local DataStoreService = game:GetService( 'DataStoreService' ) |
06 | local playerData = DataStoreService:GetDataStore( 'PlayerData' ) |
09 | local AUTOSAVE_INTERVAL = 60 |
13 | local DATASTORE_RETRIES = 3 |
20 | function PlayerStatManager:ChangeStat(player, statName, changeValue) |
21 | sessionData [ player ] [ statName ] = sessionData [ player ] [ statName ] + changeValue |
26 | local function dataStoreRetry(dataStoreFunction) |
32 | success = pcall ( function () data = dataStoreFunction() end ) |
33 | if not success then wait( 1 ) end |
34 | until tries = = DATASTORE_RETRIES or success |
36 | error ( 'Could not access DataStore! Warn players that their data might not get saved!' ) |
42 | local function getPlayerData(player) |
43 | return dataStoreRetry( function () |
44 | return playerData:GetAsync(player.UserId) |
49 | local function savePlayerData(player) |
50 | if sessionData [ player ] then |
51 | return dataStoreRetry( function () |
52 | return playerData:SetAsync(player.UserId, sessionData [ player ] ) |
60 | local function setupPlayerData(player) |
61 | local success, data = getPlayerData(player) |
64 | sessionData [ player ] = false |
68 | sessionData [ player ] = { Money = 0 , Experience = 0 } |
69 | savePlayerData(player) |
72 | sessionData [ player ] = data |
78 | local function autosave() |
79 | while wait(AUTOSAVE_INTERVAL) do |
80 | for player, data in pairs (sessionData) do |
81 | savePlayerData(player) |
87 | game.Players.PlayerAdded:connect(setupPlayerData) |
90 | game.Players.PlayerRemoving:connect(savePlayerData) |
96 | return PlayerStatManager |
I have tried using a function to print out the results, but I end up getting an empty array or nil. So what Can I do to see all the data within the DataStores.
Anyways, the goal is to print out all the information within the datastore.