I am making a datastore leaderstats
with a datastore.
Not Using DataStore2 or Profile Service by the way.
local DataStoreService = game:GetService('DataStoreService')
local PlayerPoints = DataStoreService:GetOrderedDataStore("PlayerPoints")
game.Players.PlayerAdded:Connect(function(Player)
local stats = Instance.new('Folder', Player)
stats.Name = "leaderstats"
local points = Instance.new('NumberValue', stats)
points.Name = "Points"
local isGet,Error = pcall(function()
return PlayerPoints:GetAsync(Player.UserId) or 0
end)
if isGet and not Error then
points.Value = isGet
end
if Error then
if Error == 0 then return end
error(Error)
end
points.Changed:Connect(function()
local sus,err = pcall(function()
PlayerPoints:SetAsync(points.Value, true)
end)
if sus then
print('Saved!')
end
if err then
error(err)
end
end)
game:BindToClose(function() -- BlindToClose if the game shuts down.
local sus,err = pcall(function()
PlayerPoints:SetAsync(points.Value, true)
end)
if sus then
print('Saved!')
end
if err then
error(err)
end
end)
game.Players.PlayerRemoving:Connect(function()
local sus,err = pcall(function()
PlayerPoints:SetAsync(points.Value, true)
end)
if sus then
print('Saved!')
end
if err then
error(err)
end
end)
end)
I don’t want any advertisements or anything.