StorageService
Server-side access to host-provided named stores.
- Service
game:GetService("StorageService")- Inherits
- Instance
- Replication
- Never
Behavior
StorageService opens named stores for the current place. Storage access is
server-only. A store is identified by a name and an optional scope; use the
returned Store value for reads and writes.
Durability depends on the host's storage provider. Standalone local games use
the file provider when localStorage is enabled and an application directory
is available. The standalone dedicated server keeps its store records in
session memory; those records do not survive a process restart. An embedding
host can supply a different provider. See
application settings for local storage
availability.
Store names and scopes are limited to 50 characters. Keys must be non-empty and shorter than 50 characters. Stored values can contain strings, numbers, booleans, and tables composed of those values, up to 64 KiB when encoded.
Summary
Whether the service instance is included when its containing hierarchy is cloned or saved.
The instance name.
The service's parent instance.
AddComponent(component: Component | string, values: { [string]: any }?): ComponentHandleserial onlyoverrides InstanceAdds the named component and returns its ComponentHandle.
Returns a ComponentHandle when the instance has the component, or nil when it does not.
GetComponentChangedSignal(component: Component | string, field: string?): AstScriptSignal<string>serial onlyoverrides InstanceReturns the signal for changes to this instance's component.
Returns this instance if it is an ExecutionGroup.
GetReferencing(component: Component | string, field: string?): { Instance }parallel readoverrides InstanceReturns Instances whose reference fields point to this instance.
Returns whether the instance has the specified component.
Opens a named store and returns a Store.
Removes the component and returns whether it was present.
Properties
Archivable
StorageService.Archivable: boolean = trueWhether the service instance is included when its containing hierarchy is
cloned or saved. The default is true.
Name
StorageService.Name: string = "StorageService"The instance name. The default is "StorageService".
Parent
StorageService.Parent: Instance? = nilThe service's parent instance. The default is nil.
Methods
AddComponent
StorageService:AddComponent(component: Component | string, values: { [string]: any }?): ComponentHandleAdds the named component and returns its ComponentHandle. Omitted fields use
schema defaults. Initial values are validated before they are applied.
Required components are added with it. Adding a component requires serial
execution.
GetComponent
StorageService:GetComponent(component: Component | string): ComponentHandle?Returns a ComponentHandle when the instance has the component, or nil when
it does not.
GetComponentChangedSignal
StorageService:GetComponentChangedSignal(component: Component | string, field: string?): AstScriptSignal<string>Returns the signal for changes to this instance's component. Supply a field name to observe that field. Without a field, the signal reports the changed field's name.
GetExecutionGroup
StorageService:GetExecutionGroup(): ExecutionGroup?Returns this instance if it is an ExecutionGroup. Otherwise returns the
nearest ancestor ExecutionGroup, or nil when no group contains the
instance.
GetReferencing
Returns Instances whose reference fields point to this instance. The component selects the schema; an optional field restricts the search to one reference field.
HasComponent
StorageService:HasComponent(component: Component | string): booleanReturns whether the instance has the specified component. Accepts a
Component definition or a component name.
Open
StorageService:Open(name: string, scope: string?): StoreOpens a named store and returns a Store. scope is
optional and defaults to "global". The call is server-only and yields while
the backing storage operation is prepared.
RemoveComponent
StorageService:RemoveComponent(component: Component | string): booleanRemoves the component and returns whether it was present. Fails if another attached component requires it. Removing a component requires serial execution.
Inherited members
- Properties
- ClassName
- Methods
- AddTag()ClearAllChildren()ClearTags()Clone()Destroy()FindFirstAncestor()FindFirstAncestorOfClass()FindFirstAncestorWhichIsA()FindFirstChild()FindFirstChildOfClass()FindFirstChildWhichIsA()FindFirstDescendant()GetAttribute()GetAttributeChangedSignal()GetAttributes()GetChildren()GetComponents()GetDebugId()GetDescendants()GetFullName()GetPropertyChangedSignal()GetTags()HasTag()IsA()IsAncestorOf()IsDescendantOf()RemoveTag()SetAttribute()WaitForChild()
- Events
- AncestryChangedAttributeChangedChangedChildAddedChildRemovedDescendantAddedDescendantRemovingDestroying
Example
local StorageService = game:GetService("StorageService")
local scores = StorageService:Open("scores", "season-1")
scores:Set("player-42", { score = 120, wins = 3 })
local record = scores:Get("player-42")