I made this GUI for teleport players to a game, but it won't work! Here are the scripts.
Server Script:
local TeleportService = game:GetService("TeleportService")
local currentInstance
game.ReplicatedStorage.ModEvents.TeleportPlayer.OnServerEvent:Connect(function(player, UsernameText)
local suc, errormessage = pcall(function()
local userId = game.Players:GetUserIdFromNameAsync(UsernameText)
currentInstance, _, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(userId)
end)
if suc then
TeleportService:TeleportToPlaceInstance(placeId, jobId, player)
else
print("There was an error teleporting player.")
end
end)
Local Script: (In GUI)
script.Parent.MouseButton1Click:Connect(function()
local UsernameText = script.Parent.Parent.Username.Text
game.ReplicatedStorage.ModEvents.TeleportPlayer:FireServer(UsernameText)
end)
