Hi there! I'm trying to get my game to save the player data of how many wins the player has when they leave. The problem is, it pops up with an error: Unable to cast value to function. I don't know what's wrong. Here is the code:
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:UpdateAsync(Player.UserId, Player.leaderstats.Wins.Value)
end)
I used to use DataStore:SetAsync, but it didn't work, so I switched it to UpdateAsync. If someone could help, that would be greatly appreciated! Thanks!

7 comments
What is your DataStore variable?
Well, according to this thread: https://scriptinghelpers.org/questions/38248/unable-to-cast-value-to-function-when-trying-to-update-data-in-a-datastore-with-appropriate-value , UpdateAsync isn't what you're looking for. However, I am having the same problem of SetAsync not working. What errors have you gotten from SetAsync?
Replying to Shawnyg: local DataStore = DataStoreService:GetDataStore("GameStats")
@akatak_prime -- Whenever I test the game, and then leave, it doesn't show up with any errors.
@blarp_blurp645 Yes, I have the exact same problem.
@blarp_blurp645 Oddly enough, when my scripts modify my IntValues, the game saves. However, when I manually modify them, it doesn't. Is it similar for you?
@akatak_prime I found out that saving works in-game, but not in the studio. Maybe it's that way for you?