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
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:
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
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