The link you sent isn’t working
Oh, thanks much appreciated!!!
So, I have to use HttpService
and use :GetAsync()
to get their last online time?
Yes but as I told you in my previous reply HttpService will not let you send requests to ROBLOX endpoints. The solution for this is using a proxy to send the request from their own network.
I don’t know what a proxy is and how I use it
A proxy is basically a node that acts as a retriever on behalf of a client requesting a resource.
In your case you’ll need a proxy to send a request to the api endpoint because ROBLOX servers don’t let you send requests to ROBLOX hosts
Can you please give an example I’m not sure what you mean.
Instead of directly sending the request from the ROBLOX server, you will basically ask a proxy node to send the request for you and return the data.
That’s basically a proxy in a nutshell.
How do I get a proxy node(sorry if this is weird)
If you are familiar with backend service languages like python, javascript (node), etc… and already have hosting it will be easy to make a proxy server but if you are new you could watch a tutorial, one thing I recommend for free hosting is heroku, it allows you to run node applications for free and easily.
Ok, Thank you so much! Much appreciated, thanks again
I know I’m 18 days late to this but another alternative to setting up your own server is using 000webhost or award space (I personally use award space because 000webhost wasn’t doing the job). You can host a PHP file which will send a request to the Roblox Endpoint. I will show an example and I’m assuming you know nothing about PHP.
Server Side:
- Make a PHP file in your webhost file manager
- Get UserID from global variables (we will send that in the link):
$userid = $_GET["userid"];
- then we need to send HTTP request to the endpoint:
$response = http_get("http://api.roblox.com/users/" . $userid . "/onlinestatus/");
- And finally echo that response (aka return the results)
echo $response;
Roblox Lua Side:
- Make a script (not local)
- Request our “proxy” server:
local userid = -- You will have to get the userid with remote events. Ill leave that up to you
local URL = "www.example.com/myphp.php?userid="..userid
local response = game:GetService("HttpService"):GetAsync(URL)
- JSONDecode our response because we didn’t in our PHP file
local onlinestatustable = game:GetService("HttpService"):JSONDecode(response)
- And finally pick out the value you want:
print(onlinestatustable.LastOnline)
Thank god I am online. Thank you very very very much!!!
Hi! I’ve used this as a template using the same services. Thank you it really helped me out! One question I’ve tried this a couple of times before and it worked flawless! but now I keep getting the same error back "Can’t parse JSON " Could you maybe help me? I’ve tried searching online for this without any result.
Any help is appreciated thank you!
Your code seems fine. You may have forgotten PHP tags which indicate that a file is written in PHP.
Simply change your PHP file to this:
<?php
$userid = $_GET["userid"];
$response = http_get("http://api.roblox.com/users/" . $userid . "/onlinestatus/");
echo $response;
?>
If that doesn’t work, try printing the response of the server and debug from there. Glad that this tutorial helped you out
local http = game:GetService"HttpService"
local get = http.GetAsync
local jsonDecode = http.JSONDecode
local proxyUrl = "roproxy.com" --Put your proxy's domain here.
local baseUrl = "https://api."..proxyUrl.."/users/%s/onlinestatus/"
local function getUserOnlineStatus(userId)
local requestUrl = string.format(baseUrl, userId)
print(requestUrl)
local success, result = pcall(get, http, requestUrl)
if success then
if result then
local success2, result2 = pcall(jsonDecode, http, result)
if success2 then
if result2 then
return result2
end
else
warn(result2)
end
end
else
warn(result)
end
end
local userOnlineStatus = getUserOnlineStatus(1)
print(userOnlineStatus.LastOnline) --2006-02-27T15:06:40.3-06:00
In case anyone was looking for a HttpService solution.
https://api.roblox.com/users/1/onlinestatus/
That API endpoint provides additional information too.
This API has been working fine for me until today, it started spitting out an error
HTTP 404 (Not Found)
api.roblox.com
is slowly being sunset and /users/USER_ID/onlinestatus
has been recently been removed.
For replacements, use /v1/presence/last-online and /v1/presence/users see here for the deprecation announcement for the old endpoint.
Is the replacement API down, I’ve noticed the past few days I can’t fetch any online user presence data. It will show everyone online anywhere from 4-5 days ago even when they’ve been online multiple times since then.