Ad
Log in to vote
0

Why datastore does not save the value?

Asked by 11 months ago

I'm sorry, I use Google translator!

local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")



game.Players.PlayerAdded:connect(function(player)
    local playerKey = "user_" .. player.userId
    local leaderstats = Instance.new("Model")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local Wins = Instance.new("IntValue")
    Wins.Name = "Wins"
    Wins.Value = DataStore:GetAsync(playerKey)
    Wins.Parent = leaderstats
    print(playerKey)
    while wait(5) do 
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") then
            player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1
            DataStore:SetAsync(playerKey, Wins)

        end
    end
end
end)


if you remove the "DataStore: GetAsync (playKey)", the leaderboard will show Wins, but will not save

But if you leave this line, it will not save, as well as leaderboard will not show Wins

0
You're saving the last created Wins instance, not the Value of the current player's Wins. This is all wrong. RubenKan 2583 — 11mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by
P100D 480
11 months ago
Edited 11 months ago

You're sending the actual IntValue to the datastore. Line 19 should read:

DataStore:SetAsync(playerKey, Wins)

Are you looking at the output window? It should give you some sort of error about writing the wrong type of data to an IntValue.

0
15:06:42.299 - Workspace.Save/Load Options:12: attempt to index upvalue 'DataStore' (a nil value) , Yes, your answer is correct, but it is not the solution to my problem :( TheAdmiralMaxwell 55 — 11mo
Ad

Answer this question



Ad