Hi, I’m trying to add a simple counter in my game that shows the current number of trees planted by teamtrees.org! I really support their cause, so I wanted to add a large tree in my game with a sign next to it showing the current amount of trees planted (updated every 60 seconds)
I’ve already got the site’s data using HttpService:GetAsync() and was able to put all that data on my sign every 60 seconds, the issue is I have no idea how to make any sense of the data and only get the number of trees planted.
Sorry for the late response, I didn’t see your message.
It should be fixed now. It’s published to the same model as before. You can also change line line that contains
local Trees1 = string.sub(Trees,2824+99,2824+99+10)
He gets the characters between 6436 and 6436+10, which is the text showing the trees planted. I don’t personally recommend this because any small html change, whitespace change, etc will cause it to break and need updating.
Yeah, it’s not a good solution. I don’t recommend this for anything long-term as there’s almost a 100% chance it will break. I just hacked this whole thing together due it’s short-term nature.
In lua, your best bet is of course string.find() as @CoderCrazy says above.
However, if you’re willing to get the web alternative, there are many web parsers/scrapers that would allow you to parse the HTML and directly retrieve the value.
Adding on to string.find(), here is some JavaScript code that uses regex to find the tree count. You could fairly easily convert this to lua.