Basically, I'm trying to Sava Player's Points (IntValue not Leaderstats)
But I get Print: Data Not Saved
anyone knows why?
local DATASTORE = game:GetService("DataStoreService"):GetDataStore("DATASTORE") game.Players.PlayerAdded:Connect(function(player) local Points = Instance.new("IntValue") Points.Name = "Points" Points.Parent = player local data local dataSaved, notSaved = pcall(function() data = DATASTORE:GetAsync(player.UserId.."Points") end) if dataSaved then Points.Value = data print("Data Saved") else print("Data not saved") warn(notSaved) end end) game.Players.PlayerRemoving:Connect(function(player) local dataSaved, notSaved = pcall(function() DATASTORE:SetAsync(player.UserId.."-Points", player.Points.Value) end) if dataSaved then print("Data Saved") else print("Data not saved") end end) local givePoints = game.ReplicatedStorage.givePoints givePoints.OnServerEvent:Connect(function(player) player.Points.Value = player.Points.Value + 1 end)
I found your problem. This is what you wrote on line 9:
data = DATASTORE:GetAsync(player.UserId .. "Points")
And this is what you wrote on line 24:
DATASTORE:SetAysnc(player.UserId .. "-Points", player.Points.Value)
In other words, this means that you are saving the data with different keys. To explain it a bit more, let's say I played your game and got 10 points. I leave the game, and the data is saved to 459692218-Points. The next day, I join your game once again. The code looks for a key called 459692218Points. This is not a valid save key, and it returns nil.The solution to this is to make it so line 9 has "-Points" instead of "Points"
Hope this helped!