Code (modified to always save a value of 2 for each stat for testing purposes):
Output is the exact same after multiple playthroughs:
Code (modified to always save a value of 2 for each stat for testing purposes):
Output is the exact same after multiple playthroughs:
I believe the issue is that in your pcall in the PlayerAdded connection you do not return statValue. In a pcall, the first value will be a boolean, and the second will either be an error message or something you are returning.
This is what you are doing:
local success, statValue = pcall(function()
dataStores[stat.name]:GetAsync(player.UserId)
end)
statValue will return nil in this code because it is acting as an error message, and not something you are returning. Unless your code actually fails due to the data store or something, statValue will always be nil.
**To fix this, just add the return keyword right at the start of the GetAsync() line in the middle of the pcall. This way statValue will actually be set not to an error which is nil but instead the value you actually want. **
Hope this helps!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.