I have created a Data Store script but when i click Play it does not work and always says "Argument 2 missing or nil"
local DS = game:GetService("DataStoreService")
local myDS = DS:GetDataStore("test")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
local data
local success, errormessage = pcall(function()
data = myDS:setAsync(player.UserId.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error whilst getting your data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDS:SetAsync(player.UserId.."-cash", player.leaderstats.cash.Value)
end)
if success then
print("Player Data success saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)

4 comments
The method :SetAsync() is to be used only for writing* data, it requires two arguments: The Data-Key, and the Data to be written: on line 15 you're missing this argument.
Regardless, you're calling the incorrect function. You're looking for :GetAsync().
You shouldn't be using :SetAsync() too much either, as it overrides any previous data, if your Cash value is an integer, :IncrementAsync() is something you should take a look at.
@Feahen Thank you so much!