Scripting Helpers is winding down operations and is now read-only. More info→
← Blog Home

Getting a Player's Reputation Through RBX.Lua

This piece was written by HungryJaffer. Go show him some love for the amazing article.



Now here's how it all started.

About 2 weeks ago, I was browsing scriptinghelpers, and came across this answer to this question. Amazed, I wanted to explore more possibilities of :GetAsync(). But what is GetAsync, you ask?

According to the wiki, :GetAsync(), of HttpService Sends a HTTP GET request to the supplied URL and returns the response body in a string.

So how do we use this to check a player's reputation?

Well, first, we want to get the person who will be checking, I'll use NotSoNorm as an example.

local nom = "NotSoNorm" -- Create a string variable of the name
local link  = "https://scriptinghelpers.org/user/".. nom -- We will Concatenate the link and the name. 

Now that we have that done, we're going to get into :GetAsync() . The first thing we want to do with GetAsync is get the HTML form of the website ScriptingHelpers.

The first thing we want to do when using GetAsync() is to enable HttpEnabled. This is a property of HttpService.

Then, we want to identify HttpService using :GetService()

local Service = game:GetService("HttpService")

Now that we have HttpService, we want to send a HTTP GET to the Scripting Helpers website.

local Service = game:GetService("HttpService")
local html = Service:GetAsync(link, false)

If I decided to print html, it would print the whole html representation of the web page. It would be too much to put on here.

Now that we have the HTML representation of Scripting Helpers (Specifically the profile view), we want to find the snippet of HTML that pertains to the Reputation. This can be easily done by right clicking the reputation under a player's profile, and clicking on Inspect Element.

Right click on reputation then go down to Inspect Element
Right click on reputation then go down to Inspect Element.

Imgur
This is what we will get. This line of HTML is very important.

Now that we have the line of HTML that we need, we can use our knowledge of string manipulation find this snippet of code in anyone else's username.

We will use string.match to find this specific line in the whole jumble of HTML we got through :GetAsync()

local string = [[<div>%d+ reputation</div>]]
local snippet = html:match(string)

We're almost done here. Now that we have the snippet we need, all we have to do is use string.match, and the string pattern %d+ (this represents a number of any length) to get the number of rep that the said player has.

local string = [[<div>%d+ reputation</div>]]
local snippet = html:match(string)
Reputation = (snippet:match("%d+"))

And turning this into a function and getting our end product, this is what we get.

function getRep(Player)
    local nom = Player -- Create a string variable of the name
    local link  = "https://scriptinghelpers.org/user/".. nom -- We will Concatenate the link and the    name. 
    local Service = game:GetService("HttpService")
    local html = Service:GetAsync(link, false)
    local string = [[<div>%d+ reputation</div>]]
    local snippet = html:match(string)
    Reputation = (snippet:match("%d+"))

    return ("Player has " .. Reputation .. " reputation on Scripting Helpers")
end

And voila, a function that returns the amount of rep any player on SH has.

Posted in Scripting Tips

Commentary

Leave a Comment

Perci1 says: August 28, 2015
you forgot to tab your code. shame on you.
ChipioIndustries says: August 28, 2015
I never knew how easy it was to use HttpService, this helps a ton! Thanks!
HungryJaffer says: August 28, 2015
im sorry bb, the markdown editor i used didn't want to cooperate
dragonkeeper467 says: August 28, 2015
Great Job! Just curious, how did you learn about this, I assume they didn't explain this on roblox wiki???
HungryJaffer says: August 28, 2015
from that one question posted at the top of the page
dragonkeeper467 says: August 30, 2015
lol
Spongocardo says: August 31, 2015
Glad to see the community making some tutorials for the blog, would love to see more of this. Well done!
Iweigh200lbs2u says: September 11, 2015
Scary.
TheDeadlyPanther says: September 18, 2015
Awesome! Thank you, it helped a lot.
NotSoNorm says: September 23, 2015
ohmg this was after getting unsuspended
Maxwell_Edison says: November 24, 2015
Shame indeed.
NeonTurtle2001 says: December 5, 2015
Roblox doesn't have many good script learning sites so there is few game developers and millions of other users who just buy stuff from the catalog and play games.
Prioxis says: December 8, 2015
Is there a place where we can see this in action?
rexbit says: February 13, 2016
Perci1, you forgot to capitalize your 'You', shame on you.
Perci1 says: August 28, 2016
rexbit, you forgot to capitalize your name. Shame on you. haha xD
xJathur95x says: March 4, 2019
There something i don't understand... Why Service:GetAsync(link,false) And not Service:GetAsync(link) ?