Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Datastore UpdateValue

		local asynccode = p.Name .. "pts"
		if not (ds:GetAsync(asynccode) or false) then
			ds:SetAsync(asynccode, 0) 
		end
		local asynccode2 = p.Name .. "hs"
		if not (ds:GetAsync(asynccode2) or false) then
			ds:SetAsync(asynccode2, 0) 
		end
		
		ds:UpdateAsync(asynccode, pts.Value)
		ds:UpdateAsync(asynccode2, hs.Value)

Output: Unable to cast value to function

pts.Value is a number, same for hs.Value. It must be in my wording, what is wrong?

THIS IS A SNIPPIT OF THE FUNCTION, IT RUNS UP TO HERE (I can see through prints).

I have posted this on roblox forums, you can find that here.

2 answers

UpdateAsync takes a function as a parameter, not the value you want to save.

ds:UpdateAsync(asynccode, function(oldvalue) return pts.Value end)
ds:UpdateAsync(asynccode2, function(oldvalue) return hs.Value end)

In this instance, you could simply substitute SetAsync in without having to use a function parameter. UpdateAsync is used if you anticipate problems such as multiple attempts to update happening within moments of each other, or if you want to sanitize the data being saved.

This discussion is preserved as it was. New answers, comments, and votes are closed.