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?
You aren't setting the data.
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 success, returnval = pcall(function() return myDataStore:GetAsync(player.UserId.."-stage") end) if success then stage.Value = returnval else warn(returnval) end end) game.Players.PlayerRemoving:Connect(function(player) 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)
You might've forgotten to enable API services for your game. If so you can just go to Configure game > Enable API services
.
Otherwise i don't know what could be the problem, your script seems fine.