I'm trying to save the player's money. It doesn't seem to work. API is enabled.
local DataStoreService = game:GetService("DataStoreService")
local moneyDataStore = DataStoreService:GetDataStore("moneyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue", leaderstats)
money.Name = "Money"
local data
local success, errorMessage = pcall(function()
data = moneyDataStore:GetAsync(player.UserId.."-money")
end)
if success then
money.Value = data
else warn(errorMessage)
end
if data then
--Not new player
else
if money.Value == 0 then
money.Value = 100
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
print("player removed")
local success, errorMessage = pcall(function() print("started function")
moneyDataStore:SetAsync(player.UserId.."-money", player.leaderstats.Money.Value) print("saved")
print("saved")
end)
if success then
print("Player data successfully saved")
else print("Error while saving data")
warn(errorMessage)
end
end)

3 comments
I'm having the same problem too but with my rebirth stats.
Are You Sure Your Not Throttling Your Datastores.
This is my only datastore script