The goal of my task in mind is to teleport an unknown number of players from one place to another, and communicate to the destination place how many people have teleported
With TeleportService, all of the functionality I've seen is for sending data to the Client for each player (TeleportService:GetLocalPlayerTeleportData), but this information is needed for the server of my destination place...
A solution I've thought of is to set the LocalPlayerTeleportData of each player, then have the each client fire an event to pass the LocalPlayerTeleportData to the server. The server would only save the value for the first server event fired... but this seems like a hacky way to do this.
Any tips would be appreciated, thanks!
To achieve this, you'll need to utilize ROBLOX's MessagingService. This allows messages to be sent from one server to another. MessagingService uses Topics
, which are channels that servers can post and listen for data to be transmitted through.
There are two main methods of MessagingService.
The first one is PublishAsync
. This takes two parameters: the topic's name, and the data to be sent.
The next method is SubscribeAsync
. This takes only one parameter, which is the topic's name. This will return a RBXScriptSignal, which can be connected to just as any other event.
I've made a quick example that will print whenever a player joins a game.
local ChannelName = "PlayerJoins" local MessagingService = game:GetService("MessagingService") local Players = game:GetService("Players") MessagingService:SubscribeAsync(ChannelName):Connect(function(PlayerName) print(PlayerName .. " has just joined a server of this game!") end) Players.PlayerAdded:Connect(function(Player) MessagingService(ChannelName, Player.Name) end)