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

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.