Skip to content

New example: <title> #972

@wafaans22-hub

Description

@wafaans22-hub

Description

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("PlayerSave_01") -- اسم قاعدة البيانات

game.Players.PlayerAdded:Connect(function(player)
-- 1. إنشاء قائمة المتصدرين (Leaderboard)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local points = Instance.new("IntValue")
points.Name = "Points" -- اسم النقاط (ممكن تغيره لـ Coins)
points.Parent = leaderstats

-- 2. تحميل البيانات المحفوظة
local data
local success, err = pcall(function()
	data = myDataStore:GetAsync(player.UserId)
end)

if success and data then
	points.Value = data
else
	points.Value = 100 -- هدية دخول 100 نقطة للاعب الجديد
end

end)

-- 3. حفظ البيانات عند خروج اللاعب
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
myDataStore:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)
end)

Checklist

  • I've followed all of the best practices.
  • My game has a proper name in the game properties.
  • My game package name begins with com.example..
  • My game has all events unfolded.
  • I've added myself as the author in the game properties.
  • I've included a file called "README.md" with a description in proper English, explaining what this example is doing.
  • I confirm that this game and all of its resources can be integrated to this GitHub repository, distributed and MIT licensed.
  • I've cleaned unused resources.

Game project folder

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("PlayerSave_01") -- اسم قاعدة البيانات

game.Players.PlayerAdded:Connect(function(player)
-- 1. إنشاء قائمة المتصدرين (Leaderboard)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local points = Instance.new("IntValue")
points.Name = "Points" -- اسم النقاط (ممكن تغيره لـ Coins)
points.Parent = leaderstats

-- 2. تحميل البيانات المحفوظة
local data
local success, err = pcall(function()
	data = myDataStore:GetAsync(player.UserId)
end)

if success and data then
	points.Value = data
else
	points.Value = 100 -- هدية دخول 100 نقطة للاعب الجديد
end

end)

-- 3. حفظ البيانات عند خروج اللاعب
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
myDataStore:SetAsync(player.UserId, player.leaderstats.Points.Value)
end)
end)

Game preview

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions