so im trying to make the datastore save but it does not print Player data was saved it also does not save the data. it does not give a error and i have studio api services enabled code:
local DS = game:GetService("DataStoreService")
local SaveMoney = DS:GetDataStore("SaveMoney")
local SaveDiamond = DS:GetDataStore("SaveDiamond")
local function PlayerAdded(Plr)
local Stats = Instance.new("Folder", Plr)
Stats.Name = "stats"
local Money = Instance.new("IntValue", Stats)
Money.Name = "Money"
Money.Value = SaveMoney:GetAsync(Plr.UserId) or 500
local Mone2y = Instance.new("IntValue", Stats)
Mone2y.Name = "diam"
Mone2y.Value = SaveDiamond:GetAsync(Plr.UserId) or 0
while true do
wait(300)
local MyGameStuff = script.Moneyz:Clone()
local ValueLol = math.random(10,285)
MyGameStuff.Frame.amount.Text = ValueLol
MyGameStuff.Frame.amount.CashToGive.Value = ValueLol
MyGameStuff.Parent = Plr.PlayerGui
end
end
local function PlayerRemoving(Plr)
local success, errormessage = pcall(function()
SaveMoney:SetAsync(Plr.stats.Money.Value, Plr.UserId)
SaveDiamond:SetAsync(Plr.stats.diam.Value, Plr.UserId)
end)
if success then
print("Player data was saved")
else
warn(errormessage)
end
end
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(PlayerRemoving)

3 comments
if youre doing it in studio it doesnt connect on player removed it will be fine ingame try making a private version
Well it’s most likely because you’re either trying it out on studio or because the server hadn’t got enough time to save before it shuts down. I’d recommend using BindToClose so it will save.
Do not use separate DataStores to save individual stats. I recommend you look into DataStore2 or ProfileService when you want an easy way to store data.