Is there a way to detect when a player was last online?

The link you sent isn’t working

1 Like

You have to fill in (userid) yourself
Eg: http://api.roblox.com/users/1/onlinestatus/

1 Like

Oh, thanks much appreciated!!!

1 Like

So, I have to use HttpService and use :GetAsync() to get their last online time?

1 Like

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.

1 Like

I don’t know what a proxy is and how I use it

1 Like

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

1 Like

Can you please give an example I’m not sure what you mean.

1 Like

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.

1 Like

How do I get a proxy node(sorry if this is weird)

1 Like

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.

1 Like

Ok, Thank you so much! Much appreciated, thanks again

1 Like

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:

  1. Make a PHP file in your webhost file manager
  2. Get UserID from global variables (we will send that in the link):
$userid = $_GET["userid"];
  1. then we need to send HTTP request to the endpoint:
$response = http_get("http://api.roblox.com/users/" . $userid . "/onlinestatus/");
  1. And finally echo that response (aka return the results)
echo $response;

Roblox Lua Side:

  1. Make a script (not local)
  2. 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)
  1. JSONDecode our response because we didn’t in our PHP file
local onlinestatustable = game:GetService("HttpService"):JSONDecode(response)
  1. And finally pick out the value you want:
print(onlinestatustable.LastOnline)
19 Likes

Thank god I am online. Thank you very very very much!!!

2 Likes

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.

php file

Roblox Script


Website blurred out*

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 :slight_smile:

3 Likes
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.

1 Like

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.

8 Likes

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.