i want to try making something like pet simulator X that tell the player how many of this pet exists in the whole game
Video about what i’m talking:
I think they are using Datastore or MemoryStoreService(I don’t know anything about this) but i’m not sure because datastore have a limit resquest (i don’t really know a lot about datastore) and if a lot of server running and Get and Set a the same time is possible have lost of data so i’m here for ask you if you have any idea how i can make something like this without lost of data.
[I don’t ask any script but help of idea how i can make something like this] if you need more details tell me what i missing to say
When joining the game, load the player’s pet data (possibly will have tables of each pet)? Upon the player leaving or the server shutting down due to all players leaving, save all players’ data.
Your question is quite confusing but I’m supposing you’re asking how to save a player’s data and load it again. Since you are not asking for any scripts, I will leave it up to you to understand how to do this by reading the documentation.
Basically, a simple way of replicating a Pet system is making a Folder called Pets and parent it to the player (in Players). Every time they get a new pet, add an item, such as a StringValue, to the Folder. When the player leaves, make a For loop that goes through every single StringValue in the Folder and copies all the names of the pets into a table, which then can be saved using DataStoreService
(this might not be the best method, but it will work)
Hi, and thank you but is not really what i’m looking,
What i trying to search is about this:
How many pets in the whole game exist.
but i think i have found a solution but need to try when i have time.
My idea is storing everything in a table and when the server close or every 5 min(or more, need to look about limit of resquest) is get everything in the table and add to the datastore and clear the table
(I gonna put this as the solution after i try when i have time)
Ah I see. Well, you could have a data store called TotalPets. each time someone opens an egg and gets a cat for example, the [“Cat”] in TotalPets could increase by 1. However, this is not a reliable way to do it since you will lose data if two servers access the store at the same time.
I’m pretty sure that’s exactly what DataStore:UpdateAsync() solves.
Quote from the devhub:
GlobalDataStore:SetAsync() is best for a quick update of a specific key, and it only counts against the write limit. However, it may cause data inconsistency if two servers attempt to set the same key at the same time. GlobalDataStore:UpdateAsync() is safer for handling multi-server attempts because it reads the current key value (from whatever server last updated it) before making any changes
Here my result:
(i try every 10 second and i don’t know if a need add more)
My Code:
local DatastoreService = game:GetService("DataStoreService")
local Datastore = DatastoreService:GetDataStore("Test_0.0.1")
local LastData
local NewValue = 0
local LastUpdate = 0
local TickLimit = tick() + 10
workspace.Baseplate.ClickDetector.MouseClick:Connect(function()
print("Added")
NewValue += 1
end)
workspace.Baseplate.ClickDetector.RightMouseClick:Connect(function()
end)
while wait(0.5) do
if TickLimit <= tick() then
TickLimit = tick() + 10
local success, err = pcall(function()
Datastore:UpdateAsync("Click", function(LastDataReturn)
LastDataReturn = LastDataReturn or 0
local NewData = LastDataReturn + NewValue
NewValue = 0
LastData = NewData
return NewData
end)
end)
if success then
warn(DatastoreService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.UpdateAsync))
else
warn("error")
end
print(LastData)
end
end
Bonus Question:
if is a huge data like in a table with over 999+ item and a number inside each item, it will cause delay and lose or not ?
I don’t correctly understand the resquest limit is per server or the whole game ?