DataStore won't work

This is my first time using datastore and I knew there would be an issue.

I’m using a module script to handle my data. Here is the module:

local data = {}

data.Save = function(dataStore,dataToSave,player)
	local succ, err = pcall(function()
		dataStore:SetAsync(player.UserId.."_"..dataToSave)
	end)
	
	if succ == true then
		print("Saved")
	else
		print("There was an error.")
		warn(err)
	end
	
end

return data

The error I get is Argument 2 missing or nil, meaning that the dataToSave must be nil.

And here is how I’m using the module:

DataMod.Save(MainData,plr.leaderstats.Bits.Value,plr)

Thanks if you can help.

Change this:

dataStore:SetAsync(player.UserId.."_"..dataToSave)

To this:

dataStore:SetAsync(tostring(player.UserId), dataToSave)

You are connecting data with string, so second field is missing. Thats why you code will thow this error: Argument 2 missing or nil

1 Like