Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datastore UpdateValue

Asked by
TomsGames 225 Moderation Voter
10 years ago
        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

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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.

Ad
Log in to vote
-2
Answered by 10 years ago

Ok [](http://Roblox.com

Answer this question