local Players = game.Players
local Datastore = game:GetService("DataStoreService")
local DS = Datastore:GetDataStore("DS")
function LoadFunc(Key)
local s, e = pcall(function()
local Data = DS:GetAsync(Key)
print("Got Data")
return Data
end)
if s then
print("Succesfully Got Data")
else
warn(e)
end
end
function SaveFunc(WhichData, Key)
local s, e = pcall(function()
DS:SetAsync(Key, WhichData)
end)
if s then
print("Saved")
else
warn(e)
end
end
Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Level = Instance.new("NumberValue")
Level.Value = 1
Level.Name = "Level"
Level.Parent = leaderstats
local LoadedLevel = LoadFunc("Key-Level"..plr.UserId)
if LoadedLevel then
print("Not nil")
Level.Value = LoadedLevel
print("Set Level")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
SaveFunc(plr:WaitForChild("leaderstats"):WaitForChild("Level").Value, "Key-Level"..plr.UserId)
end)
So I tried this and it still saves but it doesn't load, it doesn't print "Not nil" or "Set Level". I tried accessing the datastore using Data Editor V2 and it worked, it showed the value which was 2 and it didn't have any extra value, just 2 like intended. But when I load into the game, the Value of level isn't two, rather, it is one meaning it didn't set the value at all. I am suspecting that its because GetData() is returning nil but I do not know why

3 comments
Update: I put else warn("is nil") and it said that, so GetAsync IS returning nil
Another update: i put print(Data) in the pcall and it printed 1, which is weird
Another update: i put print(Data) in the pcall and it printed 1, which is weird