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)
Like the person said in the comments, SetAsync
requires 2 arguments and you gave it only one
i think you ment GetAsync
instead and just made a typo on line 15