I'm trying to make some kind of save file. Here's how I'm trying to do that: first I get 1 data store with a dictionary having the default values like money, then a 2nd data store to know if you already got the default one so it won't erase your progress. I have the dictionary data store go into a module (playerInfo) that I will modify and eventually save, only when you leave, so I don't use SetAsync or UpdateAsync too much. Once I enter, the default data store is successfully set and prints it in the output, but when I leave it doesn't set the new version of it. No errors in the output.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local playerSaveFile = DataStoreService:GetDataStore("playerSaveFile")
local playerFirstJoined = DataStoreService:GetDataStore("playerFirstJoined")
Players.PlayerAdded:Connect(function(player)
playerFirstJoined:SetAsync(player.UserId, "new")
end)
local playerDefaultStatus = {nothing = "here", pls = "move on"}
Players.PlayerAdded:Connect(function(player)
if playerFirstJoined:GetAsync(player.UserId) == "new" then
(here goes another part that doesn't affect in any way the next, it works so I won't include it pls no cancel)
Players.PlayerRemoving:Connect(function(player)
playerFirstJoined:SetAsync(player.UserId, "old")
local success, err = pcall(function()
playerSaveFile:UpdateAsync(player.UserId, function(oldValue)
local playerInfo = require(workspace.playerInfo)
local newValue = playerInfo.playerModuleSF or oldValue
return newValue
end)
end)
if success then
print(player.Name.."'s save file was updated.")
end
end)
Modulescript:
local PlayerInfo = {}
Players = game:GetService("Players")
function PlayerInfo.playerModule (player)
local playerModuleSF = game:GetService("DataStoreService"):GetDataStore("playerSaveFile"):GetAsync(player.UserId)
return playerModuleSF
end
Players.PlayerAdded:Connect(PlayerInfo.playerModule)
return PlayerInfo

1 comment
Ah, I see now. Thank you for everything! I didn't reaize they'd have no data and could've just used that instead of the data store, kinda new into scripting.