Check if player is online using API

How can I check if a specific player is online using the Roblox API?
I’ve looked through the Roblox API documentation, particularly under the User section, but I couldn’t find any information about checking a player’s online status. Can someone show me how to do this or give an example on how to achieve this?

https://presence.roblox.com/docs/index.html

hello!

@Xxforlife has answered there before me, so ill just give some further details :happy3:

to check if someone is online, you can use the

https://presence.roblox.com/v1/presence/users

endpoint.

making a post request to the api, with the user ids you want to check the online status of, will return several “userPresences”. if the userPresenceType is 0, it means they are offline, otherwise, they are online in some form.

here is an example of using the api for a single user:

local HttpService = game:GetService("HttpService")

local function CheckIfOnline(UserId : number)
	local ProxyURL = "roproxy.com"
	local URL = "https://presence." .. ProxyURL .. "/v1/presence/users"
	
	local Body = '{"userIds": [' .. UserId ..  ']}'
		
	local Response = HttpService:PostAsync(URL, Body) -- When actually using code, wrap this in pcall()
	local DecodedResponse = HttpService:JSONDecode(Response)
	
	local PresenceType = DecodedResponse["userPresences"][1]["userPresenceType"]
		
	if tonumber(PresenceType) == 0 then -- User is offline
		return false
	else -- User is online
		return true
	end
end

local UserIsOnline = CheckIfOnline(1) -- Change to any user id

if UserIsOnline then
	print("Online!")
else
	print("Offline!")
end

you can also check if they are in a game or in studio from the userPresenceType.

[‘Offline’ = 0, ‘Online’ = 1, ‘InGame’ = 2, ‘InStudio’ = 3, ‘Invisible’ = 4]

if you want me to explain anything in further detail, give an example in a different programming language or anything else, let me know!

2 Likes

Thanks! I will try this out and see if it works.

1 Like