Greetings all. I wanna create a “Global clicks” statistic that will contain ALL players clicks(not only one player) for this I got “IntValue” in ReplicatedStorage and main data store script in ServerScriptService. I wanna do something like this: Global clicks data saving then text(in StarterGui) changes on this data. I tried many ways like:
local DataStoreService = game:GetService("DataStoreService")
local ALLdata = DataStoreService:GetDataStore("allDataStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Values = ReplicatedStorage.Values
local worldwideClicks = Values.WorldwideClicksValue
while wait(1) do
local success, errormessage = pcall(function()
ALLdata:GetAsync(worldwideClicks, worldwideClicks.Value)
end)
end
or
local DataStoreService = game:GetService("DataStoreService")
local ALLdata = DataStoreService:GetDataStore("allDataStore")
while wait(1) do
local success, errormessage = pcall(function()
ALLdata:GetAsync("allDataStore", worldwideClicks.Value)
end)
end
and etc but they arent working or working with really long cooldown. Is there any methods that will save data that not belongs to a player and will work without cooldown?
A data store is already a collection point of all the stats you have saved on that data store for every single player that joined your game. You can see it like this: you have your datastore and this is a table that contains every player it’s data that joined your game and every player has data that you assigned that needed to be stored. I think you’re referring to the same methode they use in creating global leaderboards?
If your trying to say you want to calculate the amount of clicks of each player in a server, add them all up and then display that per server, then you can probs just do that using values which you all add up and then paste the result into a new value, which if changed changes a text label to the current value of it. (Kinda explained badly ik.).
If you want all the clicks together from all the servers though, you will probably have to do something with server ids or something else, In that case I could not help you.
local DataStoreService = game:GetService("DataStoreService")
local ALLdata = DataStoreService:GetDataStore("allDataStore")
while wait(1) do
local success, errormessage = pcall(function()
ALLdata:GetAsync("allDataStore", worldwideClicks.Value)
end)
end
Why did you used worldwideClicks.Value ? Basically, “allDataStore” is a key, no need to specify a value. It gives the value saved in the key.
Updated Code -
local DataStoreService = game:GetService("DataStoreService")
local ALLdata = DataStoreService:GetDataStore("allDataStore")
while wait(1) do
local success, errormessage = pcall(function()
ALLdata:GetAsync(player.UserId)
end)
end
Basically, normally save the data in a DataStore as you do, then when you want to get it “globally”, just use :GetOrderedDataStore() on your DataStore in which your player’s values are saved.
If you want to add up all the values in a Datastore, you’ll need to retrieve each value individually using its corresponding key, and then sum them up.
Example
local DataStoreService = game:GetService("DataStoreService")
local ALLdata = DataStoreService:GetDataStore("allDataStore")
local total = 0
-- Loop through all keys in the data store
local keys = ALLdata:GetSortedAsync(false, 1000)
for i, key in ipairs(keys) do
-- Retrieve the value associated with the key
local success, value = pcall(function()
return ALLdata:GetAsync(key)
end)
if success and type(value) == "number" then
total = total + value
else
warn("Failed to retrieve value for key: " .. tostring(key))
end
end
print("Value added up from data store: " .. tostring(total))
I know this, why are you explaining me ? There’s nothing wrong in my code, and using OrderedDataStore() is correct. What’s wrong ? And I know about DataStores dude, what you said was said by me aswell.