Hi,
to create a script, simply go to your game page (not the game itself), Settings --> API-Scripts. There you have to click at "New Script". Give it a name, write your JavaScript Code and hit save.
The sendChat is indeed the way to go, but you have to find the right trigger for your code. See at https://wiki.roll20.net/API:Events
If this doesn't help, try to look at official scripts (like "5th Edition OGL by Roll20 Companion"). This skript will reduce a Spell Slot on the character sheet (if you use the "5th Edition OGL by Roll20" sheet) and then post the new value into the chat. I'm pretty sure, if you find the right part of the code, you can copy-pase most of the code with little changes to your needs.
Hope this helps, if not, please clarify your problem a little more - which system do you use, which character sheet, what value exactly are you trying to access, and so on.