Argument 2 missing or nil on datastore setasync

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.

UpdateAsync Elevator Script:

SetAsync Elevator Script:

Joined Script:

Error:
image

If someone could just please help me out that would be great since I gotta go to bed soon

1 Like

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)

How would I print toawh(gde)?
Do I print the contents of the table? gde is a table

toawh(gde) is a function. It’s returning an object, presumably a table.

print(toawh(gde)) should output something. Print it right before you try to SetAsync()

No. gde is a table, toawh is only the function for the table.

Okay, so apparently the datastore is nil.
image

That doesn’t make any sense though because if the datastore was nil then the player joined script would have saw it and made it an empty table {}

So your error is coming from this script?

No…? It coming from this one

Could you perhaps read what I said a second time? I dont think your getting the full picture here

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?

1 Like

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.

1 Like

Join script

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.

image

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
1 Like

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

gde isn’t a datastore lol…

gde is an object of whatever :GetAsync(v.UserId) is returning, which is most likely nil.

And also, this is what you gave me to outputs
image

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 {}