If data is saved then it will print error. My script print Error. It should have saved. what did I do wrong
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("PlayerDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
local PlayerID = "player"..player.UserId
local PlayerData
local success, errormessage = pcall(function()
PlayerData = PlayerDataStore:GetSync(PlayerID)
end)
if success then
points.Value = PlayerData
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local PlayerID = "player"..player.UserId
local data = player.leaderstats.Points.Value
local success, errormessage = pcall(function()
PlayerDataStore:SetSync(PlayerID, data)
end)
if success then
print ("data saved")
else
print ("error")
end
end)

2 comments
Hmmm still error...
Hmm.... I added print after the first function and added print after the second function and it all ran, meaning that there is nothing wrong with my script, yet still it did not print "data saved" or "error"