I know you use teleporting and messaging service but how would the code go?
How can you use messaging service to find them?
If found how do you join that server?
I know you use teleporting and messaging service but how would the code go?
How can you use messaging service to find them?
If found how do you join that server?
You mean, Teleport to another game?
or
Different Servers in game?
or
Just same Server and Game just another map/place?
or
Join Friend like thing?
you broadcast a message with the player’s id
and in another script you can subscribe to the broadcast and then use a for loop to check the player’s id
if there is that player
send back another broadcast with the JobId (game.JobId
) and teleport the player to that server with the jobid.
How do I do the messaging part?
sending a message
MessagingService:PublishAsync("FindPlayer", 1234567890) --example id
receiving the message
MessagingService:SubscribeAsync("FindPlayer", function(playerId)
for i, player in pairs(game.Players:GetChildren()) do
if player.UserId == playerId then
-- do something
end
end
end)
I want it to return the message saying it has found the player and is now teleporting the person. how can I make it return the message to the person that requested the search
What you could do is send a message back to the server which initially sent the message, with said message containing the JobId of the server the target player is currently in
Something like this might work
Main Server
local data = {
JobId = game.JobId,
TargetPlayerId = InsertUserIdHere
}
messagingService:PublishAsync('SearchForPlayer', data)
messagingService:SubscribeAsync('SearchedPlayerMessage', function(data)
if data.MainJobId == game.JobId then
teleportService:TeleportToPlaceInstance(InsertPlaceIdHere, data.TargetJobId, player)
end
end)
Target Server
messagingService:SubscribeAsync('SearchForPlayer', function(data)
for i, v in pairs(game.Players:GetPlayers()) do
if v.UserId == data.TargetPlayerId then
local newData = {
MainJobId = data.JobId,
TargetJobId = game.JobId
}
messagingService:PublishAsync('SearchedPlayerMessage', newData)
end
end
end
Precciated, would try this later and ill tell if it works