I need help with a Game Teleport Script

I am trying to make it possible for players to teleport to other games/places under my main game in a GUI, I have a button and I followed a tutorial word for word and it is still not working when I press the button.

I am not really experienced with scripting and this is pretty new to me.

Here is the script
local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) --Assigns a variable to the Remote Event in the Replicated Storage

script.Parent.MouseButton1Click:Connect(function() --Runs code when the button is clicked

task.wait(1) --Wait 1 second

teleport:FireServer() --Fire the Remote Event to the server

end) --End function

Script (Under the ServerScriptService)

local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) ----Assigns a variable to the Remote Event in the Replicated Storage

local teleportservice = game:GetService(“TeleportService”) --Gets the teleport service in Roblox

local placeId = 12860998309 --Game Id, replace 6651677874 with your game Id

local players = game:GetService(“Players”) --Gets the players in the game

local player = players:GetPlayers()[1] --Gets the first player

teleport.OnServerEvent:Connect(function(player) --Code runs when the Remote Event is fired

teleportservice:TeleportAsync(placeId,{player}) --Teleports player to other game

end) --End function

You can delete the script in ServerScriptService and the Remote Event, because we dont need these. You need to insert a local script into your gui and write this:

script.Parent.MouseButton1Click:Connect(function()

task.wait(1)

game:GetService(“TeleportService”):Teleport(placeidhere,game.Players.LocalPlayer)

end)

still doesnt seem to work i dont know what the issue is

This might be a dumb question, but you are testing the teleportation in a published game right (aka not in studio)?

Basically, what happens is before you join, it gets the first player, after the game starts. The game has 0 players so it returns nil. Now you can’t teleport nil.

local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) ----Assigns a variable to the Remote Event in the Replicated Storage

local teleportservice = game:GetService(“TeleportService”) --Gets the teleport service in Roblox

local placeId = 12860998309 --Game Id, replace 6651677874 with your game Id

local players = game:GetService(“Players”) --Gets the players in the game

teleport.OnServerEvent:Connect(function(player) --Code runs when the Remote Event is fired
local player2 = players:GetPlayers()[1] --Gets the first player
teleportservice:TeleportAsync(placeId,{player2}) --Teleports player to other game

end) --End function

Basically I moved that line.
Also, you didn’t specified which player to move. The first player or the player who clicked the button? Assuming that you are teleporting first player, I wrote this. If you want to teleport the player who clicked the button, use this -

local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) ----Assigns a variable to the Remote Event in the Replicated Storage

local teleportservice = game:GetService(“TeleportService”) --Gets the teleport service in Roblox

local placeId = 12860998309 --Game Id, replace 6651677874 with your game Id

local players = game:GetService(“Players”) --Gets the players in the game

local player2 = players:GetPlayers()[1] --Gets the first player

teleport.OnServerEvent:Connect(function(player) --Code runs when the Remote Event is fired
teleportservice:TeleportAsync(placeId,{player}) --Teleports player to other game

end) --End function

You can try using an invisible block where if the plsyer step it can teleport to another invisible block.

Please read the post before replying. He wants to teleport in places, not any position.

A note is that you cant teleport to places in roblox studio.
I dont know if you know this but I had to make sure,
Also are there any errors?

Also for those who needed the code formatted.

local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) --Assigns a variable to the Remote Event in the Replicated Storage

script.Parent.MouseButton1Click:Connect(function() --Runs code when the button is clicked

task.wait(1) --Wait 1 second

teleport:FireServer() --Fire the Remote Event to the server

end) --End function

-- script under serverscriptservice 

local teleport = game.ReplicatedStorage:WaitForChild(“TeleportPlayer”) ----Assigns a variable to the Remote Event in the Replicated Storage

local teleportservice = game:GetService(“TeleportService”) --Gets the teleport service in Roblox

local placeId = 12860998309 --Game Id, replace 6651677874 with your game Id

local players = game:GetService(“Players”) --Gets the players in the game

local player = players:GetPlayers()[1] --Gets the first player

teleport.OnServerEvent:Connect(function(player) --Code runs when the Remote Event is fired

  teleportservice:TeleportAsync(placeId,{player}) --Teleports player to other game

end) --End function

Oh ok then sorry is that I am a little lazy anyways he can use: local teleportService = game:GetService(TeleportService) --pretty self explanatory, the declaration for the service
local player = game.players.LocalPlayer --declaration for the player, only works in local scripts tho, so if this is server sided you’d have to get the player elsewhere
local placeID = 9167010990 --the id of the place you’re teleporting to, it can be found in the link to your game, it should look something like this(I put two brackets around the place in the link where the place id is): https://www.roblox.com/games/[[9167010990]]/Super-Portal-Gun-Plus-BETA

teleportService:Teleport(placeID, plr.Character)–the function to teleport, use the placeID (doesn’t have to be a variable btw, just used that to make the example make more sense) as the first parameter and the character of the player that you’re teleporting as the second variable. he just have to change some stuff

His code is already formatted I guess…

Yeah I am trying to get the player who presses the button to teleport not the first player.

Well (“TeleportService”) has a red line under it in studio is that supposed to be there? Sorry once again im not at all experienced with scripting

I already gave the script below for that. The 2nd script is about that only. Please see the whole post before replying.

Is your problem solved? You didn’t marked any solution.