DataStoreService

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้จะพร้อมใช้งานในภาษาที่คุณเลือกในเร็วๆ นี้

ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

DataStoreService exposes methods for getting GlobalDataStore and OrderedDataStore objects. Data stores can only be accessed by game servers, so you can only use DataStoreService within a Script or a ModuleScript that is used by a Script.

See Data Stores for an in-depth guide on data structure, management, error handling, etc.

ตัวอย่างโค้ด

DataStore Budget

local DataStoreService = game:GetService("DataStoreService")
for _, enumItem in pairs(Enum.DataStoreRequestType:GetEnumItems()) do
print(enumItem.Name, DataStoreService:GetRequestBudgetForRequestType(enumItem))
end

สรุป

คุณสมบัติ

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Sets whether data store functions should automatically retry or not. DataStoreService does not respect this property because automatic retry has been disabled due to technical reasons. Therefore, you must implement systems for retrying operations yourself.

วิธีการ

คุณสมบัติ

AutomaticRetry

ไม่ซ้ำ
อ่านพร้อมๆ กัน
การรักษาความปลอดภัยของผู้ใช้ภายใน

Sets whether data store functions should automatically retry or not.

DataStoreService does not respect this property because automatic retry has been disabled due to technical reasons. Therefore, you must implement systems for retrying operations yourself. It is possible that automatic retry will be enabled again in the future.

วิธีการ

GetDataStore

This function creates a DataStore instance with the provided name and scope. Subsequent calls to this method with the same name/scope will return the same object.

Using the scope parameter will restrict operations to that scope by automatically prepending the scope to keys in all operations done on the data store. This function also accepts an optional DataStoreOptions instance which includes options for enabling AllScopes. See Data Stores for details on scope.

พารามิเตอร์

name: string

Name of the data store.

scope: string

(Optional) A string specifying the scope.

ค่าเริ่มต้น: "global"
options: Instance

(Optional) A DataStoreOptions instance to enable experimental features and v2 API features.

ค่าเริ่มต้น: "nil"

ส่งค่ากลับ

A DataStore instance with provided name and optional scope.

GetGlobalDataStore

This function returns the default GlobalDataStore. If you want to access a specific named data store instead, you should use the GetDataStore() function.


ส่งค่ากลับ

ตัวอย่างโค้ด

Get GlobalDataStore Instance

local DataStoreService = game:GetService("DataStoreService")
local GlobalDataStore = DataStoreService:GetGlobalDataStore()
print(GlobalDataStore.Name)

GetOrderedDataStore

This method returns an OrderedDataStore, similar to the way GetDataStore() does with GlobalDataStores. Subsequent calls to this method with the same name/scope will return the same object.

พารามิเตอร์

name: string
scope: string
ค่าเริ่มต้น: "global"

ส่งค่ากลับ

ตัวอย่างโค้ด

OrderedDataStore Basics

local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetOrderedDataStore("Points")
local function printTopTenPlayers()
local isAscending = false
local pageSize = 10
local pages = pointsStore:GetSortedAsync(isAscending, pageSize)
local topTen = pages:GetCurrentPage()
-- The data in 'topTen' is stored with the index being the index on the page
-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
for rank, data in ipairs(topTen) do
local name = data.key
local points = data.value
print(name .. " is ranked #" .. rank .. " with " .. points .. "points")
end
-- Potentially load the next page...
--pages:AdvanceToNextPageAsync()
end
-- Create some data
pointsStore:SetAsync("Alex", 55)
pointsStore:SetAsync("Charley", 32)
pointsStore:SetAsync("Sydney", 68)
-- Display the top ten players
printTopTenPlayers()

GetRequestBudgetForRequestType

This function returns the number of data store requests that the current place can make based on the given Enum.DataStoreRequestType. Any requests made that exceed this budget are subject to throttling. Monitoring and adjusting the frequency of data store requests using this function is recommended.

พารามิเตอร์


ส่งค่ากลับ

ตัวอย่างโค้ด

Print Request Budget

local DataStoreService = game:GetService("DataStoreService")
local globalStore = DataStoreService:GetGlobalDataStore()
local function printBudget()
local budget = DataStoreService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync)
print("Current set/increment budget:", budget)
end
for i = 1, 5 do
local key = "key" .. i
local success, err = pcall(function()
globalStore:SetAsync(key, true)
end)
if success then
printBudget()
else
print(err)
end
end

ListDataStoresAsync

ผลตอบแทน

Returns a DataStoreListingPages object for enumerating through all of the experience's data stores. It accepts an optional prefix parameter to only locate data stores whose names start with the provided prefix.

Only data stores containing at least one object will be listed via this function.

พารามิเตอร์

prefix: string

(Optional) Prefix to enumerate data stores that start with the given prefix.

ค่าเริ่มต้น: ""
pageSize: number

(Optional) Number of items to be returned in each page. By default is 32.

ค่าเริ่มต้น: 0
cursor: string

(Optional) Cursor to continue iteration.

ค่าเริ่มต้น: ""

ส่งค่ากลับ

DataStoreListingPages instance containing DataStoreInfo instances that provide details such as name, creation time, and time last updated.

อีเวนต์