Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why datastore does not save the value?

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

1 comment

0

You're saving the last created Wins instance, not the Value of the current player's Wins. This is all wrong.

1 answer

✓ Accepted answer

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.

1 comment

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 :(

This discussion is preserved as it was. New answers, comments, and votes are closed.