Argument 1 Missing or Nil

DSS = game:GetService("DataStoreService")
HTTPS = game:GetService("HttpService")

local CharStats = DSS:GetDataStore("MainCharacterStats")

PlrStats = {
	['Currency'] = 0,
	['CoreShape'] = "None",
	['CoreType'] = "None"
}


game.Players.PlayerAdded:Connect(function(Joinedplr)
	
	local success, CharStats = pcall(function()
		print("Data found Successfully")
		local LoadedData = CharStats:GetAsync(Joinedplr.UserId.."BasicStats")
		if LoadedData then return LoadedData
		else
			print("Making new Data")
			local NewData = CharStats:SetAsync(Joinedplr.UserId.."BasicStats",PlrStats)
			return NewData
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(Leftplr)
	local success, CharStats = pcall(function()
		local SaveData = CharStats:SetAsync(Leftplr.UserId.."BasicStats")
		if SaveData then
			print("Data saved Successfully")
			print(SaveData['Currency'])
			return SaveData
		else
			print("Something went wrong when attempting to Save Data.")
		end
	end)
end)

script.ManageMoney.Event:Connect(function(FiredPlr, amount)
	CharStats:UpdateAsync(FiredPlr.UserId.."BasicStats",function(oldvalue)
		print(tostring(oldvalue['Currency']))
		local Array = oldvalue
		Array['Currency'] = Array['Currency'] + amount
		return Array
	end)
end)

This code now works! Thanks for your help. It still wasn’t working but then I saw that I was setting the Base data when the player leaves the game instead of the updated one so I just removed the PlrStats value from the SetAsync line when the player joins and leaves.

Now that I look at it again, yea. that was an error on my part. thanks for pointing that out

1 Like

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