I’ve recently got into DataStores, so it’s basically impossible to trip on the front steps.
Keep in mind that I do know a bit about DataStores so technical language is understandable, but, explanations are helpful, too.
Loading Problem:
The problem is with loading String Values, they will cause errors:
local DataStore = game:GetService("DataStoreService")
local StatisticsDataStore = DataStore:GetDataStore("Statistics")
game.Players.PLayerAdded:Connect(function(player)
local Stats = Instance.new("Folder")
Stats.Name = "Stats"
Stats.Parent = player
local StringValue = Instance.new("StringValue")
StringValue.Value = "IDontLikeToWorkAtAll"
StringValue.Parent = Stats
local StatisticsKey = player.userId
local StatLoad = StatisticsDataStore:GetAsync(StatisticsKey)
if StatLoad then
for i, v in pairs(Stats:GetChildren()) do
v.Value = StatLoad[i] -- errors here
end
else
local StatValues = {Stats:GetChildren().Value}
StatisticsDataStore:UpdateAsync(StatLoad, StatValues)
end
end)
Here’s the error:
Is there any way to fix this error?
Saving Problem:
game.Players.PlayerRemoving:Connect(function(player)
local Stats = player:WaitForChild("Stats")
local StatValues = {Stats:GetChildren().Value}
local StatisticsKey = player.userId
local success, errormessage = pcall(function()
StatisticsDataStore:UpdateAsync(StatisticsKey, StatValues)
end)
if success then
print("success")
elseif errormessage then
warn(errormessage)
end
end)
Instead of a success, it warns:
22:28:31.744 - Unable to cast value to function
Thank you for reading, reply to any questions you have
All help is appreciated!