I’ve tested the script in studio and in a Roblox game and the data will save and load but the values will still be zero(base values). I have a part that changes the values of the leaderstats and I’ve done it manually through the console yet the data does not load when I rejoin the game.
Here is the code:
local datastore = game:GetService("DataStoreService")
local playerdata = datastore:GetDataStore("PlayerData")
game.Players.PlayerAdded:Connect(function(player)
task.wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local purchases = Instance.new("IntValue")
purchases.Name = "Purchases"
purchases.Parent = leaderstats
local rbxspent = Instance.new("IntValue")
rbxspent.Name = "Robux Spent"
rbxspent.Parent = leaderstats
local data
local data2
local success, errormessage = pcall(function()
print("test")
data = playerdata:GetAsync(player.UserId.."-purchases")
data2 = playerdata:GetAsync(player.UserId.."-robuxspent")
end)
if success then
purchases.Value = data
rbxspent.Value = data2
print("data success")
else
print("no data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
playerdata:GetAsync(player.UserId.."-purchases", player.leaderstats.Purchases.Value)
playerdata:GetAsync(player.UserId.."-robuxspent", player.leaderstats["Robux Spent"].Value)
end)
if success then
print("plr data saved")
else
print("data not saved")
warn(errormessage)
end
end)