A while ago I came across this same problem and shrugged off as a one time thing, but now a few months later the same problem arises if I make a module script and handle a datastore inside it. Nothing saves. There’s a small chance of it saving if the data is nil but any time after that it doesn’t work. Yet it seems to get the data fine.
Code:
local set = {
["Scope"] = "_Xe12A";
["DataStoreName"] = "MainStore";
["KeySecurity"] = "113"
}
local dss = game:GetService("DataStoreService")
local dataStore = dss:GetDataStore(set.DataStoreName,set.Scope)
local sss = game:GetService("ServerScriptService")
local modules = sss:WaitForChild("ServerScripts")
modules = modules:WaitForChild("Modules")
local webhook = require(modules:WaitForChild("Webhooks"))
local http = game:GetService("HttpService")
local maxAttempts = 5
local ds = {}
ds.UpdateData = function(...)
print("Updating data")
local uid,t = ...
local attempts = 0
repeat
wait(1)
local s,e = pcall(function()
dataStore:SetAsync(uid.."_player_"..set.KeySecurity,http:JSONEncode(t))
end)
until s or attempts == maxAttempts
if attempts == maxAttempts then
senddataerror(uid,t)
end
end
ds.GetData = function(uid)
local data = nil
repeat
wait(1)
local s,e = pcall(function()
data = dataStore:GetAsync(uid.."_player_"..set.KeySecurity)
end)
until s
if data then
return http:JSONDecode(data)
else
return nil
end
end
return ds
(I had to remove a big chunk of the code as its for incase of data failures and it has private keys in it)