Getting Error on line 37 I marked it with the error.

local DS = game:GetService("DataStoreService")
local timedStores = DS:GetDataStore("GameTimePlayed")
local playedTable = {}

--// Player Added //--
game.Players.PlayerAdded:Connect(function(Player)
local addFolder = Instance.new("Folder")
	addFolder.Name = "Times"
	addFolder.Parent = Player
local addTimePlayed = Instance.new("IntValue")
	addTimePlayed.Name = "TimePlayed"
	addTimePlayed.Parent = addFolder
local addMins = Instance.new("IntValue")
	addMins.Name = "Mins"
	addMins.Parent = addFolder
local addHours = Instance.new("IntValue")
	addHours.Name = "Hours"
	addHours.Parent = addFolder
local addDays = Instance.new("IntValue")
	addDays.Name = "Days"
	addDays.Parent = addFolder
	
playedTable = timedStores:GetAsync(Player.UserId, game:GetService("HttpService"):JSONEncode(playedTable))

if playedTable then
	for _,p in pairs (playedTable) do
		local In = Instance.new("IntValue")
			In.Name = p["Name"]
			In.Parent = addFolder
			In.Value = p["Value"]
		end
	end
end)

--// Player Removing //--
game.Players.PlayerRemoving:Connect(function(Player)
	for _,p in pairs (playedTable) do				--// Error:  bad argument #1 (table expected, got nil)
		table.remove(playedTable,p)
	end
	for _,i in pairs (Player.Times:GetChildren()) do
		if i then
			table.insert(playedTable,i)
			playedTable[i] = {}
			table.insert(playedTable[i],"Name")
			table.insert(playedTable[i], "Value")
			playedTable[i]["Name"] = i.Name
			playedTable[i]["Value"] = i.Value
			print(playedTable[i]["Name"])
			timedStores:SetAsync(Player.UserId,game:GetService("HttpService"):JSONEncode(playedTable))
		end
	end
end)

1 comment

0

There is no valid secondary argument to :GetAsync(). Just supply the key and the affiliated data will be attained.