Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataManager = {}
- local DataStoreService = game:GetService("DataStoreService")
- local playerDataStore = DataStoreService:GetDataStore("DATASTORE17")
- local sessionData = {}
- local function GetPlayerKey(player)
- return "Player_" .. player.UserId
- end
- function DataManager:SetupPlayerData(player)
- local playerKey = GetPlayerKey(player)
- local success, data = pcall(function()
- return playerDataStore:GetAsync(playerKey)
- end)
- if success then
- if data then
- sessionData[playerKey] = data
- else
- sessionData[playerKey] = {Tools = {}}
- end
- else
- warn(player.Name .. "'s Data failed to load")
- end
- end
- function DataManager:SavePlayerData(player)
- local playerKey = GetPlayerKey(player)
- if sessionData[playerKey] then
- local success, err = pcall(function()
- playerDataStore:SetAsync(playerKey, sessionData[playerKey])
- end)
- if success then
- print("saved")
- else
- warn(player.Name .. "'s data failed to save")
- end
- end
- end
- function DataManager:GetPlayerData(player)
- return sessionData[GetPlayerKey(player)]
- end
- return DataManager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement