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

Is this the right way to wrap updateasync around a pcall?

Asked by 4 years ago

Since Setasync dosen't have a end and its like weird

I got confused cause with setasync

you can just wrap it around simply

but I don't think I did my UpdateAsync right

The S prints true and E prints a table but I was wondering what that table was and if I did this right

local S,E = pcall(function()

    local UpdateAsync = DataStoreOfStats:UpdateAsync(Player.UserId,function(OldValue)

    return OldValue

end)

    return UpdateAsync

end)

print(S,E)

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You don't need to set the function to a variable. The pcall wraps whatever is inside of it and since UpdateAsync returns a result if it works, Success will return true or false based on whether it saved correctly.

local Success, Result = pcall(function()
    DataStoreOfStats:UpdateAsync(Player.UserId, function(OldValue)
        return OldValue and OldValue + 1 or 1
    end)
end)

print(Success and "Saved" or 'Failed', Result)
Ad

Answer this question