Answered by
4 years ago Edited 4 years ago
There are two ways to get a player. The first would be to use a DataStore
, and the other would be to use MessagingService
. I believe that the second option is the best, as it is not too reliant on a DataStore
. We are going to be trying to get the JobId
of the server that a player of the given UserId
is in. Once we have the JobId
, we can teleport to that player.
01 | local MessagingService = game:GetService( "MessagingService" ) |
02 | local TeleportService = game:GetService( "TeleportService" ) |
03 | local Players = game:GetService( "Players" ) |
05 | function GetServerData(UserId) |
08 | PlayerFoundConnection = MessagingService:SubscribeAsync( "PlayerFound" ):Connect( function (GivenUserId, GivenPlaceId, GivenJobId) |
09 | if GivenUserId = = UserId then |
10 | PlaceId = GivenPlaceId |
12 | PlayerFoundConnection:Disconnect() |
15 | MessagingService:PublishAsync( "GetPlayer" , UserId) |
16 | repeat wait() until not PlayerFoundConnection.Connected |
20 | function TeleportPlayer(Player, PlaceId, JobId) |
21 | TeleportService:TeleportToPlaceInstance(PlaceId, JobId, Player) |
24 | MessagingService:SubscribeAsync( "GetPlayer" ):Connect( function (UserId) |
25 | for _, Player in pairs (Players:GetPlayers()) do |
26 | if Player.UserId = = UserId then |
27 | MessagingService:PublishAsync( "PlayerFound" , UserId, game.PlaceId, game.JobId) |
As you can see, we have two functions: GetServerData
, and TeleportPlayer
. These functions can be referenced later on in the script.
Edit:
People are saying you need help regarding Discord as well, so let me break that down for you as well. :)
Discord has this thing called Webhooks
, which are just a way of posting messages on Discord remotely (which in this case, is ROBLOX). A webhook can be added from a server or channel's configuration. I'll be showing you how I do Discord webhooks (with my module, as it makes things simpler).
1 | local Discord = require( 3427317493 ) |
2 | local ModCallWebhook = Discord:GetWebhook( "YOUR_WEBHOOK_URL" ) |
4 | function PostModCall(Player, Message) |
6 | Content = string.format( "**Moderator call from %s (%s):\n%s**" , Player.Name, Player.UserId, Message) |