My datastore script doesn't save.
API is Enabled
Script:(Script in ServerScriptService)
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)
