I’m attempting to use UpdateAsync() to save a table, but it doesn’t seem to work out as intended. I’m currently using logs to test an attempt of it working, which saves the user’s message and who wrote it, but I’m having an issue retrieving it from the datastore. I tried doing furthermore research that could fix the issue that I’m experiencing, but doesn’t seem to refer to what I’m looking for. What’s the concurrent issue here?
-- script:
--[ Variables
local rep = game:GetService("ReplicatedStorage")
local dds = game:GetService("DataStoreService")
local lds = dds:GetDataStore("lds")
--[ Setup
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg) -- event starts
plr = tostring(plr)
local success, failed = pcall(function()
lds:UpdateAsync("lds", function(tbl) -- updates with a table
tbl = {
Message = msg, -- data.Message (if I'm right)
PlayerFrom = plr -- data.PlayerFrom (if I'm right)
}
return tbl
end)
end)
if success then
print("The datastore has been updated")
elseif failed then
warn(failed)
end
rep.LogFired:FireAllClients(msg, plr)
end)
end)
local data
local success, failed = pcall(function()
data = lds:GetAsync("lds")
end)
if success then
for _, i in pairs(data) do
print(data[i], data[i].Message, data[i].PlayerFrom)
rep.LogFired:FireAllClients(data[i].Message, data[i].PlayerFrom) -- getting their data
end
elseif failed then
warn(failed)
end
-- localscript that responds to the remote
--[ Variables
local cp = game:GetService("ContentProvider")
local rep = game:GetService("ReplicatedStorage")
local frame = script.Parent
--[ Setup
for _, i in pairs(frame:GetChildren()) do
cp:PreloadAsync({i})
end
rep.LogFired.OnClientEvent:Connect(function(msg, plr)
local clone = rep.dCard:Clone()
clone.Description.Text = msg.." /by "..tostring(plr)
clone.Parent = frame.Logs
end)