local DataStore = game:GetService("DataStoreService")
local PointsData = DataStore:GetOrderedDataStore("SugarStore1")
game.Players.PlayerAdded:Connect(function(plr)
local plrData = PointsData:GetAsync(plr.UserId)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local pointsValue = Instance.new("IntValue",leaderstats)
pointsValue.Value = plrData.sugar
leaderstats.Parent = plr
pointsValue.Name = "Sugar"
local pointsValue2 = Instance.new("IntValue",leaderstats)
pointsValue2.Value = plrData.cash
leaderstats.Parent = plr
pointsValue2.Name = "Cash"
end)
game.Players.PlayerRemoving:Connect(function(plr)
plrdata = {sugar = plr.leaderstats.Sugar.Value, cash = plr.leaderstats.Cash.Value}
PointsData:SetAsync(plr.UserId, plrdata)
print("Data Saved")
end)
That's my code, I actually started scripting recently, so I do not really understand what the problem is :/

2 comments
Oh, how do I save some data into it?
SetAsync. Like you did in playerremoving. But since you first start with a nil data value, theres no data. So it errors.