OrderedDataStore not saving data

script.Parent.Humanoid.Died:Connect(function()
	local dss = game:GetService("DataStoreService")
	for i, v in pairs(game.Players:GetPlayers()) do
		if dss:GetOrderedDataStore("BossWins"):GetAsync(v.UserId) ~= nil then
			dss:GetOrderedDataStore("BossWins"):UpdateAsync(v.UserId, function()
				local value = dss:GetOrderedDataStore("BossWins"):GetAsync(v.UserId) + 1
				print(value)
				return value
			end)
		else
			dss:GetOrderedDataStore("BossWins"):SetAsync(v.UserId, 1)
		end
	end
end)

so im trying to just save some data to an ordereddatastore, but for some reason its just not saving. i currently have 17 wins in this game, so the print statement prints 18. but if i were to kill the boss a second time, it would print 18 again instead of 19. this means the data isnt being saved and the game still thinks i have 17 wins. any idea why this is happening?

It might be because GetAsync() isn’t really needed here as UpdateAsync() will get the value for you.

^ You can add a “oldValue” parameter here in the function instead of using GetAsync().

^ You also don’t have to do this, you can also do:

oldValue = oldValue or 0

Which will default the value to 0 if it is nil.

Small nitpick but you should also put dss:GetOrderedDataStore("BossWins") in a variable.

Let me know if it works!

forgot to close this, i figured out that IncrementAsync existed and that worked

1 Like

Wow, I forgot that existed too honestly lol. I learned something new as well

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.