Hey! So, I am currently trying to make a datastore, that saves a table of my pets. As of yesterday evening, my script fails to SetAsync(player.userId, SaveTable). I have Studio API Access enabled and everything worked fine, until yesterday. Here’s a quick test script, that isn’t working in my game. The funny part is, that GetAsync is working, it’s just not printing the updated data.
Hi, im not the Best Scripter but u cant save tables, “NormalPet” îs a table first Make: NNormalPet = {"NormalPet"} NormalPet = HTTP:JsonEncode(NNormalPet)
Then în the save line instead of “NormalPet” put NormalPet
After the player joins put:
local NCode = HTTP:JsonDecode(game:GetService("DataStoreService"):GetDataStore("Pets"):GetAsync(player.UserId)
This is screenshot taken from the SetAsync() page on the Developers hub and it says that the key needs to be a string. You can do this easily by doing: tostring(player.UserId). You will also need to make the GetAsync() key a string as well.
The API page is weird because the key is automatically coerced into a string internally (I assume through tostring). You’ll notice that no error is thrown for a numeric key. Probably just says string to keep developers away from passing arbitrary datatypes as the DataStore key.
If it was not enabled it would provide an error, but in OPs case that does not seem to be the case. It seems to return nil, meaning that the GetAsync call is working.
I can confirm I am having the same issue. The line before the SetAsync part in my script will print, but the line after it won’t print and my data wont save. Really annoying bug.
I’ve already had people try to help me on Discord plus I have tested it on multiple games (including completely new places) and the same issue still occurs.
When the player leaves, the server closes before the data gets saved. You will have to use BindToClose to save the data before the server shutdowns. Check out this post that explains how to save data properly.
Yeah, that is a Roblox issue at the moment. Try it in a live game and it should work. Also you should have a loop that saves data every minute. Check out this article Documentation - Roblox Creator Hub
I Know this is like 20 days ago but i had the same issue with that and the Studio/Server was force closing to fast and it would cancel any scripts running in that time and if the data has not requested to save then you get data loss but Adding this to your data script will make sure that if server is shutdown it will kick everyone then wait 10 seconds then close the server if your in studio it will disconnect your client then wait 3 second to close the server.
The code:
game:BindToClose(function()
if not RunService:IsStudio() then
local Aplayers = Players:GetPlayers()
for i = 1,#Aplayers do
Aplayers[i]:Kick(“Server is shutting down: Please rejoin, your data will be saved.”)
end
wait(10)
else
wait(3)
end
end)
game:BindToClose(function()
if not RunService:IsStudio() then
for v, i in next, game.Players:GetPlayers()) do
i:Kick(“Server is shutting down: Please rejoin, your data will be saved.”)
end
wait(10)
else
wait(3)
end
end)