Argument 1 (and 2) missing or nil?

Hi.

Im experiencing an error with my tool datastore, which makes it break with the output error “Argument 1 missing or nil” when loading backpack, and “Argument 2 missing or nil” when saving.

Loading:
image

Saving:
image

Its weird bcuz i didnt even modified it, i was editing other things when that error appeared. I used a text comparer to compare that script with an older one and no changes, they were the same. I thought it was a studio only error, but in-game happened too. And it was working without problems some hours ago

Heres the script. Its located in ServerScriptService, tools are directly in ServerStorage



local ds = game:GetService("DataStoreService")
local store = ds:GetDataStore("ArmasXD")
local library = game.ServerStorage


local dir = {}

local function edit(player, list)
	dir[player.Name] = list
end

local function setup(player, list)
	for i = 1, #list do
		local tool = library:FindFirstChild(list[i])
		if tool then
			local clone = tool:Clone()
			local clone2 = tool:Clone()
			clone.Parent = player.Backpack
			clone2.Parent = player.StarterGear
		else

		end
	end
end



game.Players.PlayerAdded:connect(function(player)

local ready = false

	player.CharacterAdded:connect(function(char)

	local bp = player.Backpack
	local data = nil
	
	if ready == false then
		ready = true
		
		data = store:GetAsync(player.UserId)
		
		if data then
			setup(player, data)
			edit(player, data)
		end
	end	
	
	
	
	local count = 0
	
	local function adjust()
		
	if char.Humanoid.Health > 0 then
	
		local list = {}
	
		local equipped = char:FindFirstChildOfClass("Tool")
		if equipped then
			table.insert(list, equipped.Name)
		end	
	
		local tools = bp:GetChildren()
		for i = 1, #tools do
			table.insert(list, tools[i].Name)
		end
	
		if count ~= #list then
			edit(player, list)
			count = #list
		end
	end
	end
	

	
	bp.ChildAdded:connect(adjust)	
	bp.ChildRemoved:connect(adjust)	
	
	char.ChildAdded:connect(function(child)
		if child.ClassName == "Tool" then
			adjust()
		end
	end)
	
	char.ChildRemoved:connect(function(child)
		if child.ClassName == "Tool" then
			adjust()
		end
	end)	
	
	end)
end)

game.Players.PlayerRemoving:connect(function(player)
	store:SetAsync(player.UserId, dir[player.Name])
	dir[player.Name] = nil
end)



game:BindToClose(function()
	wait(3.5)
end)


If you need any other info feel free to ask me, thanks and have a great day/night.

1 Like

you want create saving tools???

1 Like

that code i placed used to do that. The problem is, now that error appears for apparently no reason and makes the tools dont save. I dont see any error tho, so thats why im asking

Why are you not making it so when a player leaves theres a local table where you will put all the equipped and unequipped items in and save that table to your datastore, Once you want your data just do :GetAsync(). What you are doing now is overkill. (I might misunderstood what you are trying to accomplish though)

Example:

local ds = game:GetService("DataStoreService")
local store = ds:GetDataStore("ArmasXD")

game.Players.PlayerRemoving:connect(function(player)
    local list = {}
    local equipped = char:FindFirstChildOfClass("Tool")
	if equipped then
		table.insert(list, equipped.Name)
	end	

	local tools = bp:GetChildren()
	for i = 1, #tools do
		table.insert(list, tools[i].Name)
	end
    store:SetAsync(player.UserId, list)
end)
2 Likes

Hi.

This is actually a very helpful idea, 96 lines reduced to like 20 lol. Never thought about that.

And well, what i was trying to explain is that my script wasnt working throwing that erros, but they worked fine few hours ago lol.

But with what you said, i think im not using that bible anymore xD. Thank you so much.

2 Likes

No problem! Glad i could help you :smile:

1 Like

You need to implement error handling in case the SetAsync call fails.