Unable to cast value to function on UpdateAsync()

hi why dfos this return unable to cast value to function? if i change update to set it doesnt but for some reason updateasync retun that

local DataStore = game:GetService('DataStoreService'):GetDataStore("jojo")


function UploadData(Player)
	if Player:FindFirstChild("Stats") then
		local Key = Player.UserId
		local Folder = Player.Stats
		local SaveList = {}
		for i,v in pairs(Folder:GetChildren())do
			SaveList[v.Name] = v.Value
		end
		DataStore:UpdateAsync(Key,SaveList)
	end
end


game.Players.PlayerAdded:Connect(function(player)
	repeat wait() until player.Character
	repeat wait() until player.Stats.FirstJoin
	
	if player.Stats.FirstJoin.Value == true then
		player.Stats.FirstJoin.Value = false
		UploadData(player)
	end
end)

I believe the issue is this line:
DataStore:UpdateAsync(Key,SaveList)
Try changing it to DataStore:SetAsync(Key,SaveList)

UpdateAsync requires a key and a function that returns the new value

DataStore:UpdateAsync(Key, function(OldValue)
	return SaveList
end)

if it is not necessary to verify the value before saving it, use SetAsync as @SeargentAUS said, it is faster

DataStore:SetAsync(Key, SaveList)
1 Like
local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("jojo")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local PlrStats = Player:WaitForChild("Stats")
	local FirstJoin = PlrStats:WaitForChild("FirstJoin")

	if FirstJoin.Value then
		FirstJoin.Value = false
		local Key = Player.UserId
		local SaveList = {}
		for _, Stat in ipairs(PlrStats:GetChildren()) do
			SaveList[Stat.Name] = Stat.Value
		end
		DataStore:SetAsync(Key, SaveList)
	end
end)