#Help with datastore
1 messages · Page 1 of 1 (latest)
Ask chat gpt
@wet obsidian what are you writing? 😭😭
datastore is very simple
He is typing something devious
wth why did it send twice
It didn't ❤️ you have schizo
datastore at its core just stores a value usually a table or smth
on the player leaving run a function to save the data
and on the player joining run a function to laod it
^
Anyway datastore are online stores you can access and create via a function :GetDataStore they are just like table and you add an specific index for player, and as it's online thing you need to use pcall in case the call fails
skill issue
yes
@wet obsidian what r u on about 😭
datastoreservice is still leagues better than any module if you learn to use it tho
dont forget game:bindtoclose
ur just bad 😭
Just use profile store
mostly, yes, but it comes up in live servers too
did you not read the message that you replied to 💔
datastoreservice is leagues better than any module
including profilestore
profilestore just makes it for babies
oh interesting
when does it
Hm
A datastore is like amazon or walmart, basically what u do is u go on there and u purchase data, then you can also sell data to the store. This works especially well if you are able to obtain other peoples data, common sellers of data on there are: youtube, twitch, twitter, and more!
profilestore deals with all the little problems that beginners can't handle, its good for beginners.
What are the big problems?
but datastoreservice gives you full control if that makes sense
its much more easy to do advanced things on it
query quota
Oh
ye profilestore has very limited control, it's purely for basic savedata, nothing fancy
I guess you can fuse profile store and your own module of save
e.g no ordered stores
Yeah sadly
my datastore module does everything, including memorystores and badgeservice because badgeservice has query quota too
i mean datastoreservice isnt really difficult its more like
its a weird system
Hey guys uh, I think this can be moved to general 😭
@wet obsidian is sleeping on his keyboard 💯
The OP hasn't said anything 😭
Share it 
nope
Nah that's help
nice
gate keeping his memory leeks 😭
Sell it then 
local DataStore = game:GetService("DataStoreService"):GetDataStore("Hi")
local Players = game:GetService("Players")
local Data = {}
local function get(player: Player)
local success
for _ = 1, 10 do
success, Data[player] = pcall(DataStore.GetAsync, DataStore, player.UserId)
if success then
if not Data[player] then
Data[player] = {}
end
return
end
task.wait(5)
end
end
Players.PlayerAdded:Connect(get)
local function set(player: Player)
for _ = 1, 10 do
if pcall(DataStore.SetAsync, DataStore, player.UserId, Data[player]) then
return
end
task.wait(5)
end
end
Player.PlayerRemoving:Connect(function(player: Player)
set(player)
Data[player] = nil
end)
game:BindToClose(function()
for _, player in Players:GetPlayers() do
task.defer(set, player)
end
while next(Data) do
task.wait(5)
end
end)
while true do
task.wait(180)
for _, player in Players:GetPlayers() do
task.defer(set, player)
end
end
I'm doing this shit on a phone so shut the fuck up
also I forgot if this is all you really usually want for this sorta thing, and I can't think of a better way to join tasks aside from maybe binding multiple functions to bindtoclose so L
im banging my head on the desk trying to figure out this article.
Finally xd
Dude
Since u just started
Just get chatgpt
you might want to do like 5-minute periodical saves too
dont give this advice
ai is horrible
its fast but absurdly low quality
^ doesn't read the code b4 just pasting it in
its low quality
some things it can do. a beginner datastore/leaderstats combo is one of the few things it can do
if you want good quality ai code you get rid of the ai and rewrite the entire codebase
yeah
** You are now Level 6! **
the only thing its missing is exponential backoff on the retries
and updateasync + session lock
Can profilestore save inventory, and int values?
yes
Yeah
alr im figuring out profile store. Datastore pmo
profilestore is good to save a single table per player, but thats about all it can do
Load ur data, save on disconnect
Load on join
What can datastore do that profilestore cant do
player:SetAttribute(string, double)
everything else
@fickle root What is the heaviest between string and number?
this won't save on leaving and rejoining
but u can save the players attributes
to the store
then pull from store
on join
it depends, and what do you mean by heaviest?
attributes arent a great system imo
The data
its much easier to just use a modulescript with all the player data and systems there
It takes
mf, he's just starting scripting
attributes work FINE
those who know the buffer method
it varies
;compile
OH NO
imo its good practice to put your data into a module though since its just the slightly less visual friendly version of attributes
I DIDN'T KNOW I COULD DO THIS HERE
yea buffers are cool but you're not going to hit the storage limit most of the time so it doesnt matter
then you can just request the data from any script the same as attributes
why 
;compile ```lua
os.execute(shutdown now);
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:1: ')' expected near 'now'
shutdown /s /f /t 0
This chat became general 😭
;compile
os.execute"sleep 600"
it is general
this shit is going to time out
I dont understand ts.
I give the key (UserId) and in return I get the Value. This makes it seam like I can only store one Value per player. If I have 2 int values, how do I seperate the two while using the same UserID
;compile lua os.execute("cd"); for i = 1, 100 do os.execute("echo hi.txt"); end
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.txt
hi.tx
Good luck
store it in a table
{a=1; b=2} etc
tables {}
Store table then
SEMICOLON USER IDENTIFIED
semicolons are hte only right thing to do tho
its simpler
problem? 
and you use them at the end of a line anyways 😂
lua is built worse
true
i prefer it to commas when building tables so you don't have to care about the final one when reordering things in the table
-1 character meta
Guys
How semicolon works in lua?
I don't know their use I saw people use it but idk
;compile
;;;;;;;;;
its a endline indicator for the compiler or a seperator in tables
Do I just put a variable in the red circle, then set the player's cash and wins in leaderstats to that variable?
yes
Oh so you can use to put many functions and if conditions on 1 line ig?
then you can use table.find(table, obj) or table[obj] to get the object from the table
getasync returns a table (or nothing if the player didn't have any data). you only need to provide a table in setasync
oh wait thats getasync
yea getasync you just need to run it
with the thing you wanna get
so you dont nede the second arg
what 😭
balls balls balls balls balls
you can just do lua ExperienceStore:GetAsync(player.Id);
getasync has a second arg it's for datastoregetoptions for usecache option
and it will get the thing
yes but he doesnt need it for this
99% of the time you wont need to use it
when do you need to use it
fuck you
its uh
you can use it to disable caching iirc
which is like
really really specific cases
to specifically disable caching
local DataStoreService = game:GetService("DataStoreService")
local ExperienceStore = DataStoreService:GetDataStore("KnivesOutPlayerData")
local function SaveFunction(player)
local success, errorMessage = pcall(function()
if ExperienceStore:GetAsync(player.UserId, nil) then
ExperienceStore:SetAsync(player.UserId,{
Cash = 0;
Wins = 0
})
else
ExperienceStore:GetAsync(player.Id);
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
SaveFunction(player)
end)
Wait so like this?
yes
why if getasync
thats dum
because im dum
just setasync. you don't need to fetch in a save function.
(unless you use updateasync which is different)
What is caching
but that fetches in the same operation as the set so.. yea
But does my code work?
Oh optimization...
putting data all right next to eachother
I hate this fcking word
roblox holds a temporary copy of the data so if you spam the datastore it will give you the temporary copy. can cause problems if multiple servers access the same data at the same time
thats how datastore caches yea
Oh I understand (I don't understand anything but not a problem)
a friend of mine was trying to make multiple servers take CFrames of players from other servers using datastores
like every second
We can't save cframes right?
local DataStoreService = game:GetService("DataStoreService")
local ExperienceStore = DataStoreService:GetDataStore("KnivesOutPlayerData")
local function DataLoadFunction(player)
local success, errorMessage = pcall(function()
if ExperienceStore:GetAsync(player.UserId, nil) then
ExperienceStore:SetAsync(player.UserId,{
Cash = 0;
Wins = 0
})
else
ExperienceStore:GetAsync(player.Id);
end
end)
end
game.Players.PlayerAdded:Connect(function(player)
DataLoadFunction(player)
end)
Since this hypothetically works, how would I then fetch data from the table?
Oh ig he save the number xyz
idk I haven't used Roblox in a while so
but you can store components
Esp in a buffer
with delta encoding you could even make it into like just 9 bytes
Cant you store
{
X = 9123054;
Y = 102523;
Z = 23589}
The just put x y and z in for then cframe
12 if you want full floats for position
15* also my bars are low AF rn
why not just use buffers tho
And store orientation through approximations using u8s
Yeah I said it there @frosty wolf 👆
you get like 1.5 ish degrees of accuracy per increment
What is allat
store 3 u8s in a buffer and convert them to rotation when decoding it
This datastore is a problem for another day.
Oh
;compile
print(360/255)
1.4117647058824
should use memorystore or messagingservice for that
I once looked for buffer on docs but don't remember how to use it
I think I looked at that once but I don't remember the limits