Hello developers!
I’ve encountered this problem for many days now for my game and I finally decided to find out the reason.
My datastore script either isn’t saving or isn’t loading the data (or both). I have an error snippet which isn’t printing out anything. I have a folder template and I’m looping through all integer, number, string and bool values to save and load the data in a datastore which the name of is the player’s user Id. Here’s the script:
function save(Player)
local DSS = _G.DSS
for _, Value in pairs(game.ServerStorage.PlayerData[Player.UserId]:GetChildren()) do
if Value.ClassName == ('StringValue' or 'IntValue' or 'NumberValue' or 'BoolValue') then
local DataStore = DSS:GetDataStore(tostring(Player.UserId))
local S, E = pcall(function()
DataStore:SetAsync(Value.Name, Value.Value)
end)
if not S then
error("Couldn't save "..Player.Name.."'s data. Error:"..E)
end
end
end
end
function load(Player)
local DSS = game:GetService("DataStoreService")
local DataFolder = script.Template:Clone()
DataFolder.Parent = game.ServerStorage.PlayerData
DataFolder.Name = Player.UserId
for _, Value in pairs(DataFolder:GetDescendants()) do
if Value.ClassName == ('StringValue' or 'IntValue' or 'NumberValue' or 'BoolValue') then
local DataStore = DSS:GetDataStore(tostring(Player.UserId))
local S, E = pcall(function()
Value.Value = DataStore:GetAsync(Value.Name)
end)
if not S then
error("Couldn't load "..Player.Name.."'s data. Error: "..E)
end
end
end
return DataFolder
end
game.Players.PlayerAdded:Connect(function(Player)
local Folder = load(Player)
local Events = game.ReplicatedStorage.Events
Events.UpdateCash:FireClient(Player, Folder.Cash.Value)
Events.UpdateCrypto:FireClient(Player, Folder.CryptoCoins.Value)
Events.UpdateTokens:FireClient(Player, Folder.Tokens.Value)
require(script.Earn)(Player)
end)
game.Players.PlayerRemoving:Connect(save)
Nothing is appearing in output from this script, does anyone know the issue to this? All help is appreciated. Thanks!