Is it just a studio problem i know i suck at datastores but ehh
no errors, also none of the warns print.
code:
local ds = game:GetService("DataStoreService")
local https = game:GetService("HttpService")
local url = no.
local function load(plr)
plr:GetAsync(plr.UserId)
end
--code will literally run on tooth picks and gum
local leadstats
local nights
local maxmode
local function save(plr, datavalue)
plr:SetAsync(plr.UserId, datavalue)
end
local function senderror(plr)
end
game.Players.PlayerAdded:Connect(function(plr)
--value mania
leadstats = Instance.new("Folder", plr)
leadstats.Name = "leadstats"
nights = Instance.new("IntValue", leadstats)
nights.Name = "nights"
maxmode = Instance.new("BoolValue", leadstats)
maxmode.Name = "maxmode"
function senderror(plr)
local message = "Something may have went terribly wrong lol ".. plr.UserId.."/"..plr.Name.. " ".. "nights: "..nights.Value.. " maxmode: ".. tostring(maxmode.Value)
local info = {
["embeds"] = {{
["title"] = "Datastore failure",
["description"] = message
}}
}
local encrpyted = https:JSONEncode(info)
https:PostAsync(url, encrpyted)
end
--that took way too long
local s, r
game:BindToClose(function()
for _, vals in pairs(leadstats:GetChildren()) do
s, r = pcall(function()
save(plr, vals.Value)
warn("Saved")
if not s then
warn ("Saving failed")
repeat save(plr, vals.Value) warn("retrying saving") until s
senderror()
end
end)
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local s, r
s, r = pcall(function()
load(plr)
warn("saved")
if not s then
warn("failed loading")
senderror()
repeat load(plr) warn("Failed retry") until s
end
end)
end)
Well, to start off why are you using some sort of web hook when the data does not load? You never get a data store using DataStoreService:GetDataStore as well you can’t use plr:SetAsync for saving data here is some code that might work.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DataStore = DataStoreService:GetDataStore("Your data store")
local function SaveData(Player)
if Player:GetAttribute("DontSaveData") then
return
end
local Success, Attempts, Error = nil, 0, nil
repeat
Attempts += 1
Success, Error = pcall(function()
DataStore:SetAsync(Player.UserId .. "-PlayerData", {Player.leadstats.nights.Value, Player.leadstats.maxmode.Value})
end)
until Success or Attempts >= 5
end
Players.PlayerAdded:Connect(function(plr)
local Success, Attempts, Data = nil, 0, nil
repeat
Attempts += 1
Success, Data = pcall(function()
return DataStore:GetAsync(plr.UserId .. "-PlayerData")
end)
until Success or Attempts >= 5
if type(Data) ~= "table" then Data = {0, false} end
if not Success then
Player:SetAttribute("DontSaveData", true)
end
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leadstats"
local nights = Instance.new("IntValue", leaderstats)
nights.Name = "nights"
nights.Value = Data[1] or 0
local maxmode = Instance.new("BoolValue", leaderstats)
maxmode.Name = "maxmode"
maxmode.Value = Data[2] or 0
end)
Players.PlayerRemoving:Connect(function(plr)
SaveData(Player)
end)
game:BindToClose(function()
for i, Player in Players:GetPlayers() do
SaveData(Player)
end
end)
Yeah. Both are. Nothing prints. Nothing happens. I remember that in studio player added doesn’t connect kn time but that’s false since the values are created.
I do those since i have a system set up to monitor data for a few days to see if there’s data loss so i know each time a value changes. I really don’t care about Update async since it literally just checks if the number is bigger.