I have a saving system in my game. It will not save any stats. Please try to help me. This is the code -
local dataserv = game:GetService("DataStoreService")
local diamondsdata = dataserv:GetDataStore("DiamondsSaveData")
local moneydata = dataserv:GetDataStore("MoneySaveData")
local multidata = dataserv:GetDataStore("MultiplierSaveData")
local rebirthdata = dataserv:GetDataStore("RebirthSaveData")
local xpdata = dataserv:GetDataStore("ExperienceSaveData")
game.Players.PlayerAdded:Connect(function(p)
local stats = Instance.new("Folder")
stats.Name = "stats"
stats.Parent = p
local diamonds = Instance.new("NumberValue")
diamonds.Name = "Diamonds"
diamonds.Value = diamondsdata:GetAsync(p.UserId) or 0
diamonds.Parent = stats
local money = Instance.new("NumberValue")
money.Name = "Money"
money.Value = moneydata:GetAsync(p.UserId) or 0
money.Parent = stats
local multi = Instance.new("NumberValue")
multi.Name = "Multiplier"
multi.Value = multidata:GetAsync(p.UserId) or 1
multi.Parent = stats
local rebirth = Instance.new("NumberValue")
rebirth.Name = "Rebirth"
rebirth.Value = rebirthdata:GetAsync(p.UserId) or 1
rebirth.Parent = stats
local xp = Instance.new("NumberValue")
xp.Name = "Experience"
xp.Value = xpdata:GetAsync(p.UserId) or 0
xp.Parent = stats
game.Players.PlayerRemoving:Connect(function()
diamondsdata:SetAsync(p.UserId)
moneydata:SetAsync(p.UserId)
multidata:SetAsync(p.UserId)
rebirthdata:SetAsync(p.UserId)
xpdata:SetAsync(p.UserId)
end)
end)

3 comments
@TheRealPotatoChips that script does not work
you have to publish your game and enable API services to use datastore
I did that quite a long time ago.