I want to make a data store system and people usually say you should only use one DataStore and multiple Keys. And in my research i found out that theres a function of the DataStoreService called :GetGlobalDataStore(), so shouldnt i be using this funcion instead of :GetDataStore() as im only going to use one data store for my game?
I’m pretty sure :GetGlobalDataStores() is used when you want something stored across servers, like a server-wide countdown or achievement, while normal datastores are for specific players.
I’m reviving this post but there’s some important clarifications I need to make, since the documentation is unclear and almost misleading. This is the top post on google and has 1k views so I’m assuming this is a topic a lot of people are searching up. When I started writing my own database module, I was confused too.
-
GlobalDataStores do not exist.
To clarify, I mean the actual class called GlobalDataStore DOES NOT represent an actual object you can create.
There is only DataStore and OrderedDataStore. GlobalDataStore is merely an abstract class that DataStore and OrderedDataStore inherit from, or in other words, a thing to hold the functions that both Datastores & OrderedDataStores share, like GetAsync(), SetAsync(), etc. In the docs, the pages for actual DataStore and OrderedDataStore only show their unique functions. -
GetDataStore does not return a GlobalDataStore
As of this post, the documentation page for this function is wrong. GetDataStore returns a DataStore.
I get the intention of whoever wrote this page, since technically DataStore inherits from GlobalDataStore, and most of the common methods like GetAsync() are on the doc page for GlobalDataStore, not DataStore. However, if you value accuracy and clarity, the EXACT return type is DataStore. -
GetGlobalDataStore does not return a GlobalDataStore
This is funny because of the name. Like with the above bullet point, this function returns a DataStore. Yeah, technically DataStores inherit from GlobalDataStores so it’s not necessarily wrong, but the exact return type is just plain old Datastore.
What does the Global in this function mean then? It’s a misnomer. It means “unnamed”, as in GetUnnamedDataStore. This function is identical to GetDataStore, except it doesn’t require a name for the DataStore, so it always returns the same DataStore. -
All datastores and ordered data stores are global
By “global” I mean shared across all servers for a particular game. To clarify for the second poster, there’s no such difference between “global” or “normal” datastores. If I call GetDataStore(“money”), it will always return the same DataStore, regardless of the server.
Should I use GetGlobalDataStore() or GetDataStore()? There is no difference. If your game only has one datastore, you could do
local MyDataStore = DataStoreService:GetGlobalDataStore()
or you could just pick some random name for your one and only data store.
local MyDataStore = DataStoreService:GetDataStore("MyOneAndOnly")
What do I prefer? I like naming my datastores so I do the second.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.