I need to know the best way to save a player’s data. I’m working on an Inventory system for pets and I need to save the player’s pets. I wanted to try to do this with Values. Each time a player gets a pet, I add a BoolValue to a folder parented to the player and then save those values using DataStore creating a separate key for each value…which is un-efficient. If anyone knows a way to do this please tell me, or if you can get a link for me that would be great.
Thanks!
Just use a table with keys for the name of the stat and the value being the value. Here’s more information on tables: https://developer.roblox.com/en-us/articles/Table. You’d just save it in a datastore like anything else.
3 Likes
This might be the solution, but I’m not sure how I would add more values to the table
The article I linked explains that: https://developer.roblox.com/en-us/articles/Table#writing-into-dictionaries.
The value of a new or existing dictionary key can be defined by indicating the key name in brackets (
[key]
) followed by=
and then the value:
local testDictionary = { FruitName = "Lemon", Sour = true } -- Change value of existing keys testDictionary["FruitName"] = "Cherry" testDictionary["Sour"] = false -- Insert new key-value pair testDictionary["FruitCount"] = 10 print(testDictionary["FruitName"]) print(testDictionary["Sour"]) print(testDictionary["FruitCount"])
4 Likes