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

DataStore not saving data when player leaves: Unable to cast value to function?

Asked by 4 years ago

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!

0
What is your DataStore variable? Shawnyg 4330 — 4y
0
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? akatak_prime 48 — 4y
0
Replying to Shawnyg: local DataStore = DataStoreService:GetDataStore("GameStats") blarp_blurp645 63 — 4y
0
@akatak_prime -- Whenever I test the game, and then leave, it doesn't show up with any errors. blarp_blurp645 63 — 4y
View all comments (3 more)
0
@blarp_blurp645 Yes, I have the exact same problem. akatak_prime 48 — 4y
0
@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 48 — 4y
0
@akatak_prime I found out that saving works in-game, but not in the studio. Maybe it's that way for you? blarp_blurp645 63 — 4y

Answer this question