How do I fix my Teleport system (MessagingService) not working?
Asked by
4 years ago Edited 4 years ago
I'm trying to make a system where the player can teleport to any server by typing in the username.
This code that I have does not work
Here is the code (made by @OptimisticSide):
01 | local function GetServerData(UserId) |
04 | PlayerFoundConnection = MessagingService:SubscribeAsync( "PlayerFound" , function (givenId, givenPlaceId, givenJobId) |
05 | if UserId = = givenId then |
06 | placeId = givenPlaceId |
08 | PlayerFoundConnection:Disconnect() |
12 | MessagingService:PublishAsync( "GetPlayer" , UserId) |
13 | repeat wait() until not PlayerFoundConnection.Connected |
17 | MessagingService:SubscribeAsync( "GetPlayer" , function (UserId) |
18 | for _, player in pairs (game.Players:GetPlayers()) do |
19 | print ( "UserId: " .. UserId) |
20 | if player.UserId = = UserId then |
21 | MessagingService:PublishAsync( "PlayerFound" , UserId, game.PlaceId, game.JobId) |
27 | local function TeleportPlayer(placeId, jobId, player) |
28 | TeleportService:TeleportToPlaceInstance(placeId, jobId, player) |
31 | game.ReplicatedStorage.TeleportToPlayer.OnServerEvent:Connect( function (username) |
32 | local UserId = game.Players:GetUserIdByNameAsync(username) |
33 | loccal placeid, jobid = GetServerData(UserId) |
34 | TeleportPlayer(placeid, jobid, player) |
Output:
UserId: 0x0434518381 -- The userId is a table instead of an integer value
Something is not working here. If anyone know's the answer please tell me. Thanks in advance.