Hello, after having different problems with datasave I changed my script and I made this one which seems already better than the old one, everything works very well. However: I looked on the internet and I could understand through some posts that my script is globally bad because there is neither DataStore2/Corounes/ProfileService (and other things that I don’t know/maintain) which makes me doubt. I’ve finished my game now but I’m not publishing it because I’m afraid of having data leaks after a few days. Could someone tell me if it is possible to improve this script ? And how? I tried Courones but with the table I use I didn’t succeed.
Or maybe my script is safe ? So i don’t know i’m lost with all these informations
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("creaturedata")
local function saveData(player)
local cTable = {}
for _, creature in pairs(player:WaitForChild("Creatures"):GetChildren()) do
table.insert(cTable,creature.Name)
end
local success, errorMsg = pcall(function()
DataStore:SetAsync(player.UserId, cTable)
end)
if success then
print("data")
else
print("no data")
warn(errorMsg)
end
end
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "Creatures"
folder.Parent = player
local data
local success, errorMsg = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
if success and data then
for _, cName in pairs(data) do
if workspace.Creatures:FindFirstChild(cName) then
local newval = Instance.new("BoolValue")
newval.Name = cName
newval.Parent = folder
print("data2")
else
print("no data2")
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMsg = pcall(function()
saveData(player)
end)
if success then
print("data3")
else
print("no data3")
end
end)
game:BindToClose(function()
for _, plr in pairs(game.Players:GetPlayers()) do
local success, errorMsg = pcall(function()
saveData(plr)
end)
if success then
print("data4")
else
print("no data4")
end
end
end)
even if the improvement of the script is minimal it will already know that and I will be happy. I would like to understand what are the probabilities of losing my data? Does it happen frequently? Because it’s happens it will be the death of the game insured this kind of problem
Please I don’t ask for much. Just to know if from your knowledge I can improve my script and if so how? Otherwise is this script above likely to have data memoy problems ? thank you very much
Thank you for your answer
No particular reason, I just need to find out how it all works because I have never used this data. So you use two scripts, right? A datasave1 and a datasave2
I have read on the forum by many people that the use of the DataStore2 is not nearly as necessary as what is said everywhere. From the script above ? Someone could tell me how I could improve it. Thank you
Player kick seems to be good for you ? Do you know which module i have to add to data history, and why i have to delete data if a player resquet for ? Thank you. I really appreciate your help i need it
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "Creatures"
folder.Parent = player
local data
local success, errorMsg = pcall(function()
data = DataStore:GetAsync(player.UserId)
end)
local savedata = Instance.new("BoolValue", player)
savedata.Name = "SaveData"
savedata.Value = true
if success and data then
for _, cName in pairs(data) do
if workspace.Creatures:FindFirstChild(cName) then
local newval = Instance.new("BoolValue")
newval.Name = cName
newval.Parent = folder
print("data2")
else
print("no data2")
player.savedata.Value = false
player:Kick("Your data failed to load ! Please rejoin.")
end
end
end
end)
Well first off, you have to be able to delete player data because it’s an obligation under data protection laws. So you have to be able to delete all player records, and not just from your data stores.
Here is more information: About GDPR and CCPA
For data versioning, look under versioning here: Data Stores
But you could also do it a couple other ways. It’s really up to you
local success, errorMsg = pcall(function()
while task.wait() do
wait(180)
saveData(player)
print("autosave")
end
end)
end)
One problem I still have is this. I understand that it is related to the fact that the server is overloaded with “GetAsync” or “SetAsync” requests (I forget), however I don’t know how to fix this problem with my script. Thank you very much
It’s because of the request limits on datastores. They scale to the amount of players in your game, but in studio because you playtest often, you’re hitting the limits. There is a way to check what your current request limit budget is though here: DataStoreService:GetRequestBudgetForRequestType
Thank you again for the time you take to me! however i’m pretty sur there is something wrong who create this warning message everytime (every every).
Anyway, do you know where i need to place the
“1. A retry method in case the datastore fails to retry getting the data” ?
On playerAdded ? PlayerRemoved ? BindToclose ? On the local function Data Save ? Everywhere ?
1 A retry method in case the datastore fails to retry getting the data → it’s OK
2 A way to kick a player if the datastores fail, so they don’t override/lose previous data → it’s OK
3 Data store history to revert to last save version → if someone can help me to achieve this please. I want to publish my game
If anyone knows how to revert to the latest version of the data save a would be really great. Otherwise I won’t push it any further and will try to ask again in a few days. Thanks