Datastore failing to cast value to function

Hey everyone! So I made an onJoin local function which also contains the function for when a child is added.

The pcall is throwing the error of “Failed to cast value to function” while in attempt to datastore a table.

I am using UpdateAsync(), so I don’t really know if that is affecting it?

Anyway, my code is below, and if anyone knows the issue, please tell me! Thanks!

	
	if Data then
		if type(Data) == "string" then
			local gun = Data
			
			local sv = Instance.new("StringValue")
			sv.Name = gun
			sv.Parent = plr:WaitForChild("OwnedGuns")

			updateOwned:FireClient(plr, sv.Name)
		elseif type(Data) == "table" then
			for i, gun in pairs(Data) do
				local sv = Instance.new("StringValue")
				sv.Name = gun
				sv.Parent = plr:WaitForChild("OwnedGuns")

				updateOwned:FireClient(plr, sv.Name)
			end
		end
	else		
		warn("New player or data corrupted")
		local sv = Instance.new("StringValue")
		sv.Name = "AK47U"
		sv.Parent = plr:WaitForChild("OwnedWeapons")
		
		updateOwned:FireClient(plr, "AK47U")
	end
	
	wait()
	
	plr:WaitForChild("OwnedGuns").ChildAdded:Connect(function(child)
		local suc, err = pcall(function()
			Owned:UpdateAsync(plr.UserId, child.Name)
		end)
		
		if not suc then
			print(err)
		else
			print("Success!")
		end
	end)```
1 Like

You aren’t using UpdateAsync() Properly.
Read more about it here:

It’s different from :SetAsync()
You need to provide a function:

Wiki page on it:
here

I tried to use setAsync, however when I tried this, I got a massive issue of the database having over 100+ of the same value.

If that issue could be fixed, I could discard updateAsync() because it doesn’t look like a very good fit for what I am trying to do.