The property Value of the IntValue only accepts numbers, in this line you trying to set the value to nil, just set it to zero, should work.
if success and currentcoins ~= nil then
coins.Value = currentcoins
else
coins.Value = 0
end
Also, I don’t recommend saving the DataStore value directly from the IntValue property. Since the IntValue is parented inside leaderstats, and leaderstats is parented inside the Player, everything inside the player is automatically destroyed when the player leaves. This means that if there’s any delay or if the DataStore call takes too long when the player is leaving, the value might be lost before it’s saved.
You are making an Int value so it doesn’t make sense for this be ever be nil., because nil is not a number. You can’t do this, and it should be coins.Value = 0 or if you have a different default integer value that should be set
You could also consider doing something like this:
nil is not a number and IntValue.Value only accept number type. just replace coins.Value = nil with coins.Value = 0 at line 17. (nil is like NULL pointer , 0 (for C/C++) not nothing. Luau treat it as an invalid internal type)
but I wanna give some advice:
Why dont you provide better failure handling? You should support the retry mechanism. Delivering your code into a bad production environment can cause data to not be available properly because :GetAsync sometimes fails and your practices do not comply with any common handling rules.
For new developer . exploring DataStoreService is a good option though. However, professional network logic is needed behind it to handle complex session conflicts. If you don’t plan to learn this type of knowledge, you can use community modules like DataStore2 (by Roblox) and ProfileStore ProfileService (by loleris) DocumentService (by Sublivion) Datakeep (by noahrepublic)
I fixed it. It was because I was incrementing my coin value using a LOCAL script so it only changed the value on the CLIENT and not the server, so the server recognized the coin value as 0.