#Help with datastore

1 messages · Page 1 of 1 (latest)

frosty wolf
#

Can someone help me with datastoring? I have watched multiple videos and read multiple documents and I can't seem to get it. I am just tyring to store and load a Wins and Cash int value in leaderstats

fickle root
still bison
#

@wet obsidian what are you writing? 😭😭

crystal hornet
teal reef
#

wth why did it send twice

crystal hornet
teal reef
#

datastore at its core just stores a value usually a table or smth

crystal hornet
teal reef
#

and on the player joining run a function to laod it

crystal hornet
#

^

teal reef
#

the hard part is the service being a hot pile of shit

#

that doesnt work half the time

still bison
fickle root
teal reef
crystal hornet
#

@wet obsidian what r u on about 😭

teal reef
#

datastoreservice is still leagues better than any module if you learn to use it tho

fickle root
#

dont forget game:bindtoclose

crystal hornet
teal reef
#

iirc

fickle root
#

mostly, yes, but it comes up in live servers too

teal reef
#

datastoreservice is leagues better than any module

#

including profilestore

#

profilestore just makes it for babies

teal reef
#

when does it

still bison
#

Hm

crystal hornet
fickle root
#

profilestore deals with all the little problems that beginners can't handle, its good for beginners.

teal reef
#

its much more easy to do advanced things on it

fickle root
still bison
#

Oh

fickle root
#

ye profilestore has very limited control, it's purely for basic savedata, nothing fancy

still bison
#

I guess you can fuse profile store and your own module of save

fickle root
#

e.g no ordered stores

still bison
fickle root
#

my datastore module does everything, including memorystores and badgeservice because badgeservice has query quota too

teal reef
#

i mean datastoreservice isnt really difficult its more like

teal reef
crystal hornet
#

what Hey guys uh, I think this can be moved to general 😭

still bison
#

@wet obsidian is sleeping on his keyboard 💯

crystal hornet
#

The OP hasn't said anything 😭

fickle root
#

nope

crystal hornet
still bison
wet obsidian
#
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

frosty wolf
crystal hornet
#

Since u just started

#

Just get chatgpt

wet obsidian
#

you might want to do like 5-minute periodical saves too

crystal hornet
#

to do it

#

Litterally 😭

#

Use the Luau gpt

teal reef
#

ai is horrible

#

its fast but absurdly low quality

crystal hornet
teal reef
#

its low quality

fickle root
teal reef
#

if you want good quality ai code you get rid of the ai and rewrite the entire codebase

fickle root
#

it wont be any good but it's a start

#

or just use print's code

teal reef
#

yeah

runic archBOT
#

studio** You are now Level 6! **studio

fickle root
#

the only thing its missing is exponential backoff on the retries

#

and updateasync + session lock

frosty wolf
#

Can profilestore save inventory, and int values?

fickle root
#

yes

frosty wolf
#

alr im figuring out profile store. Datastore pmo

fickle root
#

profilestore is good to save a single table per player, but thats about all it can do

crystal hornet
#

Load on join

frosty wolf
crystal hornet
fickle root
#

everything else

still bison
#

@fickle root What is the heaviest between string and number?

crystal hornet
#

this won't save on leaving and rejoining

#

but u can save the players attributes

#

to the store

#

then pull from store

#

on join

fickle root
teal reef
still bison
teal reef
#

its much easier to just use a modulescript with all the player data and systems there

still bison
#

It takes

crystal hornet
#

attributes work FINE

teal reef
#

yea

wet obsidian
fickle root
#

it varies

wet obsidian
#

;compile

lavish parcelBOT
#
Critical error:

You must attach a code-block containing code to your message or quote a message that has one.

wet obsidian
#

OH NO

teal reef
#

imo its good practice to put your data into a module though since its just the slightly less visual friendly version of attributes

wet obsidian
#

I DIDN'T KNOW I COULD DO THIS HERE

fickle root
#

yea buffers are cool but you're not going to hit the storage limit most of the time so it doesnt matter

teal reef
wet obsidian
#

;compile

::_::print""goto _
#

MUAHAHAHHAA

lavish parcelBOT
#
Program Output



























































































































































































































































fickle root
#

why agony

teal reef
#

;compile ```lua
os.execute(shutdown now);

lavish parcelBOT
#
Program Output
/opt/wandbox/lua-5.4.7/bin/lua: prog.lua:1: ')' expected near 'now'

teal reef
#

;compile```lua
os.execute("shutdown now");

#

whys it not running

fickle root
crystal hornet
#

Very important

#

and relavent cat

still bison
#

This chat became general 😭

wet obsidian
#

;compile

os.execute"sleep 600"
crystal hornet
wet obsidian
#

this shit is going to time out

crystal hornet
#

ima go dev

#

cya nerds

frosty wolf
#

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

teal reef
#

;compile lua os.execute("cd"); for i = 1, 100 do os.execute("echo hi.txt"); end

lavish parcelBOT
#
Program Output
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
still bison
lavish parcelBOT
#
Critical error:

Wandbox replied with: 504 Gateway Timeout
This could mean WandBox is experiencing an outage, or a network connection error has occured

fickle root
#

{a=1; b=2} etc

wet obsidian
teal reef
#

its simpler

fickle root
teal reef
#

and you use them at the end of a line anyways 😂

wet obsidian
#

in C maybe

#

Lua is built different

teal reef
#

lua is built worse

wet obsidian
#

true

fickle root
#

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

wet obsidian
#

-1 character meta

teal reef
#

i prefer it for that and that its right next to enter

#

'

#

l

#

;

still bison
#

Guys

#

How semicolon works in lua?

#

I don't know their use I saw people use it but idk

wet obsidian
#

;compile

;;;;;;;;;
lavish parcelBOT
#
teal reef
frosty wolf
# teal reef tables {}

Do I just put a variable in the red circle, then set the player's cash and wins in leaderstats to that variable?

still bison
teal reef
#

then you can use table.find(table, obj) or table[obj] to get the object from the table

fickle root
teal reef
#

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

frosty wolf
#

what 😭

wet obsidian
#

balls balls balls balls balls

teal reef
fickle root
teal reef
#

and it will get the thing

teal reef
fickle root
#

99% of the time you wont need to use it

wet obsidian
#

when do you need to use it

teal reef
#

1% of the time

#

obv

wet obsidian
#

fuck you

teal reef
#

its uh

#

you can use it to disable caching iirc

#

which is like

#

really really specific cases

fickle root
frosty wolf
# teal reef you can just do ```lua ExperienceStore:GetAsync(player.Id);```
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?

frosty wolf
#

because im dum

fickle root
#

just setasync. you don't need to fetch in a save function.

teal reef
#

yea you should do

#

yea

fickle root
#

(unless you use updateasync which is different)

still bison
fickle root
#

but that fetches in the same operation as the set so.. yea

teal reef
#

method

frosty wolf
teal reef
#

its good but i dont want to explain it

#

at its core its just

still bison
teal reef
#

putting data all right next to eachother

still bison
#

I hate this fcking word

fickle root
# still bison What is caching

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

teal reef
#

thats how datastore caches yea

still bison
wet obsidian
#

a friend of mine was trying to make multiple servers take CFrames of players from other servers using datastores

#

like every second

frosty wolf
#
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?

still bison
#

Oh ig he save the number xyz

wet obsidian
#

but you can store components

#

Esp in a buffer

#

with delta encoding you could even make it into like just 9 bytes

frosty wolf
wet obsidian
#

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

still bison
wet obsidian
#

you get like 1.5 ish degrees of accuracy per increment

still bison
wet obsidian
frosty wolf
#

This datastore is a problem for another day.

still bison
#

Oh

wet obsidian
#

;compile

print(360/255)
lavish parcelBOT
#
Program Output
1.4117647058824

wet obsidian
#

that

#

in degrees

fickle root
still bison
#

I once looked for buffer on docs but don't remember how to use it

wet obsidian