I want the values of the strings to save when you leave and when you rejoin there same as you left them. I can’t seem to get the saving function to work I get no errors. I tried multiple videos and looked up some stuff to try to make it work and tested it.
local DSS = game:GetService("DataStoreService"):GetDataStore("crazystuff324423432")
function save(plr)
local s = {}
for i, v in pairs(plr:WaitForChild("Data"):GetChildren())do
s[i] = {[v.Name] = v.Value}
end
DSS:SetAsync(plr.UserId, s)
end
game.Players.PlayerAdded:Connect(function(Player)
local folder = Instance.new("Folder", Player)
folder.Name = "Data"
local hair = Instance.new("StringValue", folder)
hair.Name = "Hair"
hair.Value = "Hair1"
local success, errorm = pcall(function()
local loaded = DSS:GetAsync(Player.UserId)
if loaded then
print(loaded)
for i, v in pairs(loaded)do
print(i)
end
end
end)
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetChildren())do
save(v)
end
end)
It doesn’t look like your code has any sections that add the loaded data to the StringValues.
You wrap your entire piece of code in a pcall to hide all the error messages. If you ever do that, make sure to either handle the error, print the error, or be certain all possible errors are fine.
I think the problem is that you input Player.UserId into GetAsync, but GetAsync takes a string while UserId is an int/number.
You also should save data when players leave the game, not just when the server ends.
Edit:
The print function prints tables pretty nicely into the output, I don’t think this needs to be changed. Would definitely be neater to just use string keys instead though (@OP don’t use string keys and number keys though, that will cause string keys to be ignored).