Hello! My question is how do you save multiple values using DataStore? I already have a DataStore script. It used to save one value. I tried to make it save 2 recently. I tried so many times and the DataStore script just becomes worse.The first value doesn't even save anymore. Thanks for helping.
script:
game.Players.PlayerAdded:Connect(function(plr)
local h = Instance.new("Folder",plr)
h.Name = "leaderstats"
local n = Instance.new("NumberValue",h)
n.Name = "Trophies"
n.Value = 0
local m = Instance.new("NumberValue",h)
m.Name = "Stage"
m.Value = 1
local i = Instance.new("NumberValue",plr)
i.Name = "Coins"
i.Value = 100
local data
local data2
local success, errormessage = pcall(function()
data = DataStore:GetAsync(plr.UserId.."-Trophies")
end)
if success then
n.Value = data
else
print("error")
warn(errormessage)
end
do
local success, errormessage = pcall(function()
data2 = DataStore:GetAsync(plr.UserId.."-Coins")
end)
if success then
n.Value = data2
else
print("error")
warn(errormessage)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
DataStore:SetAsync(plr.UserId.."-Trophies",plr.leaderstats.Trophies.Value)
end)
if success then
print"success"
else
print"error"
warn(errormessage)
end
do
local success, errormessage = pcall(function()
DataStore:SetAsync(plr.UserId.."-Coins",plr.Coins.Value)
end)
if success then
print"success"
else
print"error"
warn(errormessage)
end
end
end)

5 comments
need your code
ok wait a minute
there
i made a video on how to save an inventory
Please remember to format your code before pasting it here