Evident by the title, I am by no means a good scripter. I need help adding more values to datastores. To make the datastore, I followed an older tutorial by AlvinBlox. In the tutorial, it doesn’t tell me how to add multiple datastores. Could someone please amend my code to work as intended?
Loading
players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gemstones = Instance.new("IntValue")
gemstones.Name = "Gemstones"
gemstones.Parent = leaderstats
local lvl = Instance.new("IntValue")
lvl.Name = "lvl"
lvl.Parent = leaderstats
local xp = Instance.new("IntValue")
xp.Name = "xp"
xp.Parent = player
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-gemstones")
end)
if success then
gemstones.Value = data
else
print("There was an error when getting data")
warn(errormessage)
end
end)
Saving
local function save(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-gemstones", player.leaderstats.Gemstones.Value)
end)
if success then
print("Player data saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end
I didn’t want to copy the function to add more (because I heard there is a limit to GetAsync)
In addition to the already saving “Gemstones”, I would like “xp” and “lvl” to save as well. (This should be obvious considering that it is already written in the code, but I just want to provide as much detail as possible to hopefully make it easier for anyone helping me. Thanks!
Edit: I also want to add that the tutorial instructed me to concacnate the userId to the name of the value intentionally to make it easier to add more values.