The error message for the First Function prints "nil"
local DataStoreService = game:GetService("DataStoreService")
local PlayerDataStore = DataStoreService:GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local points = Instance.new("IntValue", leaderstats)
points.Name = "Points"
points.Value = 4
local PlayerID = player.UserId
local data
local success, errormessage pcall(function()
data = PlayerDataStore:GetAsync(PlayerID)
end)
if success then
local points = player.leaderstats.Points
points.Value = data
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data = player.leaderstats.Points.Value
local PlayerID = player.UserId
local success, errormessage = pcall(function()
PlayerDataStore:SetAsync(PlayerID, data)
end)
if success then
print("Player data has been saved")
else
warn(errormessage)
end
end)

1 comment
thanks it works now