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):
local function GetServerData(UserId) local placeId, jobId PlayerFoundConnection = MessagingService:SubscribeAsync("PlayerFound", function(givenId, givenPlaceId, givenJobId) if UserId == givenId then placeId = givenPlaceId jobId = givenJobId PlayerFoundConnection:Disconnect() end end) MessagingService:PublishAsync("GetPlayer", UserId) repeat wait() until not PlayerFoundConnection.Connected return placeId, jobId end MessagingService:SubscribeAsync("GetPlayer", function(UserId) for _, player in pairs(game.Players:GetPlayers()) do print("UserId: " .. UserId) if player.UserId == UserId then MessagingService:PublishAsync("PlayerFound", UserId, game.PlaceId, game.JobId) return end end end) local function TeleportPlayer(placeId, jobId, player) TeleportService:TeleportToPlaceInstance(placeId, jobId, player) end game.ReplicatedStorage.TeleportToPlayer.OnServerEvent:Connect(function(username) local UserId = game.Players:GetUserIdByNameAsync(username) loccal placeid, jobid = GetServerData(UserId) TeleportPlayer(placeid, jobid, player) end)
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.