My DataStore system doesnt work, the issue is in the SetAsync part but i dont know where, Do you spot anything bad in this script? (I specify that there are no error messages)
local success, errormessage = pcall(function()
-- Save player money
MoneyDataStore:SetAsync(player.UserId, player.MoneyPlayer.Dollars.Value)
-- Save player items
for i, ValuesData in ipairs(player.ItemsData:GetChildren())do
CharacterDataStore:SetAsync(player.UserId, ValuesData.Value)
end
end)
wait()
if success then
print("DataSaved")
else
print("ErrorDataSaved")
warn(errormessage)
end
First to start off, you are spamming the SetAsync method, in which when you try to get data from CharacterDataStore:GetAsync(player.UserId), it’ll just be a ValuesData.Value.
(To make this explanation more simple, let’s say you had 3 values for a character. Name, age, and date of birth. It would set one of these values, not all of them like a table, that you are trying to do.)
Secondly, in-studio, game.Players.PlayerRemoving sometimes doesn’t work, so you’ll have to try legitimately in-game, or any other sort of alternatives, unless it starts working in studio, or it’s been working.
And to your main issue, I don’t see anything wrong prior the code
local data = {}
for i, ValuesData in ipairs(player.ItemsData:GetChildren()) do
data[ValuesData.Name] = ValuesData.Value -- save the value to the table
end
CharacterDataStore:SetAsync(player.UserId, data) -- save the table
Yes I think so too, here is the part of the script that gets the data:
local data
local Moneydata
local success, errormessage = pcall(function()
data = CharacterDataStore:GetAsync(player.UserId)
Moneydata = MoneyDataStore:GetAsync(player.UserId)
end)
if success then
print("DataLoaded")
player.MoneyPlayer.Dollars.Value = Moneydata
local values = {}
for i, itemValue in ipairs(player.ItemsData:GetChildren())do
values[itemValue.Name] = itemValue.Value
end
print (values)
values = data