Unable to cast value to function

I’m trying to assign a value to a UserId in a DataStore, but I’m getting the error, Unable to cast value to function. Here is the script:

local DataStoreService = game:GetService("DataStoreService")
local passStore = DataStoreService:GetDataStore("PassStore")

local Players = game:GetService("Players")

Players.PlayerRemoving:Connect(function(plr)
	print("plr removing")
	local statsFolder = plr:WaitForChild("StatsFolder")
	local pass = statsFolder and statsFolder:FindFirstChild("Pass")
	
	if pass.Value == true then
		local success, errorMessage = pcall(function()
			passStore:UpdateAsync(plr.UserId, "passed")
		end)
		if not success then 
			warn(errorMessage)
		end
		if success then
			print(plr.UserId)
		end
	end
end)

How do I fix this?

UpdateAsync takes a function, not a value. You might want SetAsync instead.

2 Likes

adding to @JarodOfOrbiter ,
use updateasync only if the old value matters to you.

1 Like