Alright, so I’m having some problems when it comes to the HttpService:JSONEncode() line under the saveData function. For some reason it stops the script after the playerInfo:SetAsync() and it does not yield any errors or nothing. The 1 is printed but the 2 is not. I genuinely have no idea what the issue is except for the JSONEncode() function.
If something is unclear please say so and I’ll try my best to make this process easier for all parties involved.
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local playerInfo = DataStoreService:GetDataStore("playerInfo")
local HttpService = game:GetService("HttpService")
local System = require(game:GetService("ServerScriptService")["General System"].System)
local DataTable = require(script.dataTable)
function loadProfile(plr)
playerInfo:SetAsync(plr.userId.."-1", HttpService:JSONEncode(DataTable))
end
function saveData(plr)
print(1)
playerInfo:SetAsync(plr.userId.."-1", HttpService:JSONEncode({
["Stats"] = {
["Dollars"] = {
["Value"] = System.shrinkValue(plr.leaderstats.Dollars.Value);
["Multiplier"] = 0;
["Boost"] = 0;
};
["Scraps"] = {
["Value"] = System.shrinkValue(plr.leaderstats.Scraps.Value);
["Multiplier"] = 0;
["Boost"] = 0;
};
["Rebirths"] = {
["Value"] = System.shrinkValue(plr.leaderstats.Rebirths.Value);
["Multiplier"] = 0;
["Boost"] = 0;
};
};
["Items"] = {
};
["Backpacks"] = {
};
["Finders"] = {
};
["Pets"] = {
};
}))
print(2)
end
Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
if playerInfo:GetAsync(plr.userId) == nil then
loadProfile(plr)
end
local dollars = Instance.new("IntValue")
dollars.Name = "Dollars"
dollars.Parent = leaderstats
dollars.Value = System.expandValue(HttpService:JSONDecode(playerInfo:GetAsync(plr.userId.."-1")).Stats.Dollars.Value)
local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
rebirths.Value = System.expandValue(HttpService:JSONDecode(playerInfo:GetAsync(plr.userId.."-1")).Stats.Rebirths.Value)
local scraps = Instance.new("IntValue")
scraps.Name = "Scraps"
scraps.Parent = leaderstats
scraps.Value = System.expandValue(HttpService:JSONDecode(playerInfo:GetAsync(plr.userId.."-1")).Stats.Scraps.Value)
end)
Players.PlayerRemoving:Connect(function(plr)
local s, e = pcall(function()
saveData(plr)
print(2)
end)
if not s then
warn(plr.Name.."'s data was not saved correctly on leaving! Error: "..e)
end
end)
while true do
wait(120)
for i,v in pairs(Players:GetChildren()) do
local s, e = pcall(function()
saveData(v)
end)
if not s then
warn(v.Name.."'s data was not saved correctly! Error: "..e)
end
end
end