DataStore2 - Incrementing Value Error - attempt to perform arithmetic (add) on nil and number

Hello everyone,
I have recently started using DataStore2 and I came with Incrementing problem.
Basically whenever I tried to Increment the value I get error: “attempt to perform arithmetic (add) on nil and number”.
I tried to fix it but I didnt come with any solution.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		for i,v in pairs(Lbs) do
			if v.Name == LootboxChosen then
				if not game:GetService("Players"):FindFirstChild(player.Name) then return end
				local DataStore2 = require(1936396537)
				local NormalLootboxData = DataStore2("NormalLootbox", player)
				if v.Name ~= "None" and game:GetService("Players"):FindFirstChild(player.Name) then
					print("Not None")
					if v.Name == "NormalLootbox" then
						print("Lootbox")
						NormalLootboxData:Increment(1)
						print("Received")
					end
				end	
			end
		end
	end)
end)

Thanks for any solution!

1 Like

I’m getting the same issue by trying to increment a Money datastore with an IntValue.Value …

Try adding a 0 at the end (It is a default value)
NormalLootboxData:Increment(1,0)

I figure it out, the problem was actually in the datastore I used modified one from this video How to Use DataStore2 on Roblox - Easiest Method - YouTube and I had instead of =~, == so I can normally use normal DataStore Incrementing :slight_smile:

1 Like