I am having a bit of trouble with this Updating my DataStore. I am trying to update the value of a table of booleans, but it is not passing the variable for the boolean through the pcall function. Here is my code (if there is a better way to write this, by all means, please correct me.)
local function SetData(player)
if not EndingsData then
for i, Ending in ipairs(EndingsTable) do
local success, err = pcall(function()
EndingsData:SetAsync(player.UserId..Ending.Name, Ending.Value)
end)
if success then
print("Successfully set data")
else
print("Error")
warn(err)
end
end
else
local function UpdateData(Ending)
local NewValue = Ending.Value
return NewValue
end
for i, Ending in ipairs(EndingsTable) do
local success, err = pcall(function()
EndingsData:UpdateAsync(player.UserId..Ending.Name, UpdateData(Ending))
end)
if success then
print("Successfully set data")
else
print("Error")
warn(err)
end
end
end
end
The output keeps saying “attempt to index nil with name” which means the variable is not getting through. However, when I print the variable outside of the pcall, it works fine. Any and all help is appreciated!