Join player in the same game, just different server?

How can I detect if a player has joined the game, but from a different server, then get their server info and join them? All while in-game but a different server.
Without being friends with them.

I’m sure this is simple, but I couldn’t find anything on it to help me out.

1 Like

Not possible within the engine right now. The Lua API doesn’t expose any event for that.

With Messaging Service (coming soon), you could potentially inform all servers in real-time about any player that joins, and then hook up events to that. (Probably excessive for your use case?)

Then:

9 Likes

It depends on what you mean by “detect”. GetPlayerPlaceInstanceAsync returns enough information to know if the player is playing the game in question, but you would have to initiate it from your server somehow, so that your server could periodically check (polling). There is no event to attach to automatically; that wouldn’t scale nicely if all servers got notified of each others’ joins :grimacing:. Well, a Datastore Changed event may be able do this, if players check in and out via a global datastore and connections are used sparingly (there are limits, as with all DS accesses). Your own webserver running a service would be a safer bet.

1 Like

This works, if they are currently in the game the code is running in which is what I was getting at. Thanks.
One more question tho, is there a way to get if a user is online using their ID?

Only if the other user is friends with the specified user. You can’t get this data for non-friends. Two functions exist which can allow you to retrieve this data:

  • GetFriendsAsync, which returns a FriendPages object. Each page contains tables of data which consist of a UserId, Username and IsOnline boolean.
  • GetFriendsOnline, which returns a table of friend data that’s slightly more detailed than GetFriendsAsync if a player’s online status is relevant. You can get their UserId, Username, last time online, online status, last location, PlaceId, GameId and what they were doing when they were last online (on mobile, in-game, on the website or in studio).

Alternatively, there’s an endpoint available for this data. I wouldn’t recommend using the endpoint since functionality for getting a player’s online status already exists as a method you can utilise in-game, however. This endpoint also contains far less data than GetFriendsOnline. That and all of the data returned from this endpoint can already be obtained from the aforementioned functions as well as others (for instance, for getting a user’s thumbnail, there’s GetUserThumbnailAsync).

A plus, you can use data from GetFriendsOnline in conjunction with GetPlayerPlaceInstanceAsync to get the server (instance) that a friend is in and then TeleportToPlaceInstance to get a user to the server of said friend.

3 Likes

Yeah, I know about the friends but with what I’m trying to do I don’t think that’d be the way.
Would there be a way to get this info from in-game?
https://presence.roblox.com/docs#!/Presence/post_v1_presence_users

Okay so here is an issue with using this method. I must be using it wrong or something.

This code goes threw a list of user ids I have set in a ModuleScript and if the user is in the game(any server) it’s suppose to create a new frame with a join button on a SurfaceGui.
It only works if that user is in that server, it will not get users in different server.
So my question here is, what am I doing wrong and how can I make this get the user from any server in the same game?

function freshUsers()
	for i,v in pairs(script.Parent.Frame:GetChildren()) do if v:IsA("Frame") then v:Destroy() end end
	for i,v in pairs(tubers) do
		for _,p in pairs(game.Players:GetPlayers()) do
			pcall(function()
				local success, errorMessage, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(v.ID)
				if success and not(script.Parent.Frame:FindFirstChild(getUsername(v.ID))) then
					local n = script.Parent.holder:Clone()
					n._Name.Text = getUsername(v.ID)
					n.Name = getUsername(v.ID)
					n.Visible = true
					n.Parent = script.Parent.Frame
					for _,P in pairs(game.Players:GetPlayers()) do
						RE.TuberButton:FireClient(P,n.Join,v.ID)
					end
				end
			end)
		end
	end
end
while wait() do
	spawn(function() freshUsers() end)
	for i = 15,0,-1 do
		script.Parent.TextLabel.Text = "youtubers ("..i..")"
		wait(1)
	end
end

I honestly am not too sure how to use this, I’ve never tried before so it’s kinda confusing me.
Any info on this will help, I just want to have a list of user ids, and refresh it every so often and if the user with that id is in the game let other users join them.

  1. This bug is still in effect: TeleportToPlaceInstance is broken w/ out error message
    So don’t check the success value, just check if the jobId isn’t nil.
  2. You will not be able to get the game instance of a player when that player has their privacy settings sufficiently high. That’s intended.
  3. You are calling GetPlayerPlaceInstanceAsync way more than is necessary. Just do 1 loop first where you get the job instances for all the userids in your list, and then distribute that to all players. No need to run the same loop every time for each player.
4 Likes

I don’t understand what you’re asking. The functions I listed are ones you use in-game. They provide everything that the endpoint you posted does.

Thank you this was the issue. I should have done a little more research on TeleportToPlaceInstance.
Also thanks for pointing out I was using it too much, fixed that too.

Sorry for the bump, but does anyone know if this has been fixed yet? (The problem with the success return value)

1 Like