How do I save multiple values into a Roblox Datastore?

Hey, I’m making a tempban system and I wanna save two values, endEpoch and Reason. How do I do so?
Thanks

Just put these values in a dictionary and save it.

{
    endEpoch = 0,
    Reason = ""
}
1 Like

What I usually like doing is to save data using attributes. I’d do:

local table = player:GetAttributes()

GetAttributes() returns a dictionary of all the instance’s attributes, so essentially if your players had the attributes “endEpoch” and “Reason”, then the “table” we just set would look like this:

 {
  endEpoch = 0,
  Reason = ""
}

Then to save your table you would do:
DataStore:SetAsync(Plr.UserId, table)

Now you have a table of everything you need saved to the player’s data, when a player joins the server you could load his data by doing:

local data = DataStore:GetAsync(Plr.UserId, table)
player:SetAttribute("endEpoch", data.endEpoch or 0)
player:SetAttribute("Reason", data.Reason or "")

If you didn’t know you could retrieve a value in a dictionary by doing table.key, in this case data.endEpoch or data.Reason.
So yeah, that’s how I personally use attributes to save and load player data, hope this helped.

1 Like

And how would I read from that?

Thanks, I think I will rather save normally but thank you!

You would do table.key as I had just explained in my previous reply.

table = {
   endEpoch = 0,
   Reason = ""
}

endEpoch = table.endEpoch
Reason = table.Reason
1 Like