I am extremely confused on datastores.
First I tried using UpdateAsync(). That gave no errors in the output but it didn’t save the data either. At first I thought every time I joined it set my data back to {}, but I soon found out that the elevator script wasn’t updating/setting the data at all.
I’m assuming datastore:SetAsync(v.UserId, toawh(gde)) is the line that’s erroring?
Can you print(toawh(gde)) and see what that outputs? Also for future reference, try to post your code on the actual post surrounded by ``` at the beginning and ` `` at the end for formatted code. (without the spaces)
To be fair, it’s hard to figure out what script is giving you a problem when you label your code with images and without line numbers. Can you update the original post with the actual code?
Adding on, you should name your variables something relevant and easy to identify. It’s difficult to pinpoint the problem when we don’t know what the variables are supposed to represent at first glance.
local datastore = game:GetService("DataStoreService"):GetDataStore("Floorsbeen")
game.Players.PlayerAdded:Connect(function(p)
local e = Instance.new("Folder",p)
e.Name = "Floors"
local success, err = pcall(function()
datastore:GetAsync(p.UserId)
end)
if not success then
print('bruh')
datastore:SetAsync(p.UserId,{})
else
print('hey')
for i,v in pairs(game:GetService("DataStoreService"):GetDataStore("Floorsbeen"):GetAsync(p.UserId)) do
print(v)
end
local s = datastore:GetAsync(p.UserId)
if type(s)=="table" then
for i,v in pairs(s) do
local r = Instance.new("BoolValue",e)
r.Name = tostring(v)
end
else
print('jae')
datastore:SetAsync(p.UserId,{})
end
end
end)
Elevator script
for i, v in pairs(game.Players:GetChildren()) do
if v.Character.InElevator.Value==true then
local datastore = game:GetService("DataStoreService"):GetDataStore("Floorsbeen")
local gde = datastore:GetAsync(v.UserId)
local tse = false
if table.find(gde,e) then
tse = true
end
local function toawh(as)
local reutg = table.insert(as,e)
return reutg
end
if tse==false then
for erer, asag in pairs(toawh(gde)) do
print(asag)
end
datastore:SetAsync(v.UserId,toawh(gde))
Instance.new("BoolValue",v.Floors).Name = e
end
I think you’re getting confused with DataStores and tables.
This error is telling you that the table you’re trying to parse (and essentially save) is nil – this has nothing to do with the actual DataStore or process of you trying to save that data.
Elevator script
-- try running this and post what it outputs
for i, v in pairs(game.Players:GetChildren()) do
if v.Character.InElevator.Value==true then
local datastore = game:GetService("DataStoreService"):GetDataStore("Floorsbeen")
local gde = datastore:GetAsync(v.UserId)
local tse = false
if table.find(gde,e) then
tse = true
end
local function toawh(as)
local reutg = table.insert(as,e)
return reutg
end
if tse==false then
for erer, asag in pairs(toawh(gde)) do
print(asag)
end
print(toawh(gde))
--datastore:SetAsync(v.UserId,toawh(gde))
Instance.new("BoolValue",v.Floors).Name = e
end
Do you know that gde is the datastore for the player, and that datastore is a table?
gde is a table, and reutg is the function that inserts into the table
Also, gde is suppose to be a table. Idk why it isnt because in the join script, if it sees that its anything but a table, it makes it an empty table {}