I made this GUI for teleport players to a game, but it won't work! Here are the scripts.
Server Script:
01 | local TeleportService = game:GetService( "TeleportService" ) |
02 | local currentInstance |
03 |
04 | game.ReplicatedStorage.ModEvents.TeleportPlayer.OnServerEvent:Connect( function (player, UsernameText) |
05 | local suc, errormessage = pcall ( function () |
06 | local userId = game.Players:GetUserIdFromNameAsync(UsernameText) |
07 | currentInstance, _, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(userId) |
08 | end ) |
09 | if suc then |
10 | TeleportService:TeleportToPlaceInstance(placeId, jobId, player) |
11 | else |
12 | print ( "There was an error teleporting player." ) |
13 | end |
14 | end ) |
Local Script: (In GUI)
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | local UsernameText = script.Parent.Parent.Username.Text |
3 | game.ReplicatedStorage.ModEvents.TeleportPlayer:FireServer(UsernameText) |
4 | end ) |
its pretty easy just delete your scripts and add this one to the gui
01 | wait( 1 ) |
02 | player = game.Players.LocalPlayer |
03 | button = script.Parent |
04 | local debounce = false |
05 |
06 | function helpme() |
07 | if not debounce then |
08 |
09 | debounce = true |
10 | Torso = player.Character.Torso |
11 | Torso.CFrame = game.Workspace.part.CFrame -- change the "part" to where ever you want player to go |
12 |
13 | end |
14 | end |
15 | button.MouseButton 1 Click:connect(helpme) |
16 |
17 | while true do wait() |
18 | debounce = false |
19 | end |
try to do
01 | local TeleportService = game:GetService( "TeleportService" ) |
02 | local currentInstance |
03 |
04 | game.ReplicatedStorage.ModEvents.TeleportPlayer.OnServerEvent:Connect( function (player, UsernameText) |
05 | local suc, errormessage = pcall ( function () |
06 | local userId = plr.UserId |
07 | currentInstance, _, placeId, jobId = TeleportService:GetPlayerPlaceInstanceAsync(userId) |
08 | end ) |
09 | if success then |
10 | TeleportService:TeleportToPlaceInstance( 0 , player, jobId) --- repleace the 0 to your place id that you are teleporting to |
11 | else |
12 | print ( "There was an error teleporting player." ) |
13 | end |
14 | end ) |