#Question about datastores

1 messages · Page 1 of 1 (latest)

inland plank
#

I have a script which someone helped me make (thank you Von 🙏) which loads a set of values into the player upon joining, i havent done datastores before and before i move onto giving it a go, im wondering if i can data store values that get added to the player, rather than values that are already on the player, it might be a dumb straightforward question to someone who a shred of experience on datastores but i’d like an answer before i move forward

hollow flume
#

game:GetService("DataStoreService")

#

you get data you store em in the server for later

#

this works even offline btw

#

that how games keep your money saved up

#

attach the data to the player id

#

when game is loaded load the data and apply it to a gui or anything like that

inland plank
#

So even if the values are loaded into the player upon joining it can still be datastored?

hollow flume
#

yes

inland plank
#

Thank you 🙏

wise smelt
hollow flume
#

Yes using the roblox escape key thingy

inland plank
#

And maybe this is a stupid question, dont feel obligated to answer but how do i check if theres valid data?

hollow flume
#

You dont

inland plank
hollow flume
#

You just gamble your luck

hollow flume
wise smelt
#

in this case i mean valid data as in everything but NIL

#

-# nil is essentially nothing

#

we can just check the players data and confirm its NOT nil

hollow flume
#

Remember nan is different than nil

wise smelt
#
if playerdata ~= nil then
  --load your data
end
wise smelt
inland plank
#

So im good to go and i can just load the data and as long as i load it after the values are in the player its fine?

radiant inletBOT
#

studio** You are now Level 1! **studio

inland plank
#

Fuck off mee6

hollow flume
#

dont be rude

inland plank
#

HE FLAGGED MY MESSAGE

#

I HATE HIS FACE

hollow flume
inland plank
#

Why cant i use nil?

wise smelt
#
local DSS = game:GetService("DataStoreService")
local Datastore = DSS:GetDataStore("MyStore")

game.Players.PlayerAdded:Connect(function(p)
    local Key = p.UserId
    local PlayerData = Datastore:GetAsync(Key)
    if PlayerData ~= nil then
        -- Data exists!
        print(PlayerData)
    else
        -- Data doesnt exist
        warn("NO DATA FOUND!")
    end
end)

game.Players.PlayerRemoving:Connect(function(p)
    local Key = p.UserId
    Datastore:SetAsync(Key, 10)
end)

here is a basic example of a datastore

hollow flume
#

nan meant not a number

#

Nil means zero/nothing

inland plank
#

Right right

inland plank
#

I will be checking out coral game

hollow flume
wise smelt
hollow flume
wise smelt
#

nil again essentially is nothing so in certain cases you could use it

#

such as throwing an object away from workspace but keeping it in memory

mypart.parent = nil
#

you can still access "mypart" but it wont be in the workspace

hollow flume
#

I suggest storing it in replicated storage tho

wise smelt
inland plank
hollow flume
inland plank
#

Just to clarify….

#

Models have no need in terms of datastores right?

wise smelt
#

if you have say a building game you would want to save a table with parts and plot positions in datastore

#

then load the plot

hollow flume
#

I would racomend that static objcet are loaded in locally

#

And that models that change overtime be stored in data

radiant inletBOT
#

studio** You are now Level 5! **studio

inland plank
wise smelt
inland plank
radiant inletBOT
#

studio** You are now Level 2! **studio

hollow flume
#

Your place changes overtime

wise smelt
radiant inletBOT
#

studio** You are now Level 9! **studio

wise smelt
hollow flume
wise smelt
#

so plant growing! gotcha!

hollow flume
#

Ok so i gtg rn

#

Ty for helping

wise smelt
inland plank
wise smelt
#

anyways, feel free to post further questions here., ill check out other threads.