local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
-- if game.Workspace.DistributedGameTime > 3 then
-- repeat wait(1) until game.Workspace.DistributedGameTime > 3
-- end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Parent = leaderstats
local data
local success, errormessage = pcall(function()
myDataStore:GetAsync(player.UserId.."-stage")
end)
if success then
stage.Value = data
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local StageValue = player.leaderstats.Stage.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-stage", player.leaderstats.Stage.Value)
end)
if success then
print("Data saved")
else
warn(errormessage)
end
end)
Here is my script, I followed a tutorial online and got this. It doesn't work. Before you say this is a copy of my previous post, no one will answer it since there is already an answer (that doesn't work.) Now before you post an answer please check if it works because I don't want this to happen again. No errors, Data saved was printed, but I don't get the stat number back when joining, am I doing something wrong? The tutorial I watched was this. I've also looked in other places for data stores, none worked. Am I doing something wrong?

4 comments
On line 19, you define data, but you fail to give it a value on line 21. Shouldn't line 21 be something like data = myDataStore:GetAsync(player.UserId.."-stage")?
Side note: You don't have to define a new function when using pcall. Here's an example of how to avoid that in your case:
local success, data = pcall(myDataStore.GetAsync, myDataStore, player.UserId.."-stage")If the pcall errors,
datawould be the error message. If pcall does not error, thendatawould be the return value of the GetAsync method.Thank you!