Hello, i want to know what’s wrong in my code, i copy the place ID correctly and it didnt worked in my roblox player game
Script:
local Players = game:GetService("Players")
local playerList = Players:GetPlayers()
-- Teleports
local TeleportService = game:GetService("TeleportService")
local gameID1 = 6328942781
--local gameID2 = 6328942781
--local gameID3 = 6328942781
if mapName == "Celestial by Xepharim" then
print("mapa celestial")
TeleportService:Teleport(gameID1, playerList)
elseif mapName == "Circuit Board" then
print("mapa circuit")
elseif mapName == "The Oil Rig by PetitePYT" then
print("mapa oil rig")
end
for _, Player in pairs(game.Players:GetPlayers()) do
if mapName == "Celestial by Xepharim" then
print("mapa celestial")
TeleportService:Teleport(gameID1, playerList)
elseif mapName == "Circuit Board" then
print("mapa circuit")
elseif mapName == "The Oil Rig by PetitePYT" then
print("mapa oil rig")
end
end
end
Hi there! I was evaluating your code and found for loop to be the solution to your problem!
Try something like the following:
local Players = game:GetService("Players")
-- Teleports
local TeleportService = game:GetService("TeleportService")
local gameID1 = 6328942781
local gameID2 = 6328942781
local gameID3 = 6328942781
if mapName == "Celestial by Xepharim" then
print("mapa celestial")
for _,player in pairs(Players:GetPlayers()) do
TeleportService:Teleport(gameID1, player)
end
elseif mapName == "Circuit Board" then
print("mapa circuit")
for _,player in pairs(Players:GetPlayers()) do
TeleportService:Teleport(gameID2, player)
end
elseif mapName == "The Oil Rig by PetitePYT" then
print("mapa oil rig")
for _,player in pairs(Players:GetPlayers()) do
TeleportService:Teleport(gameID3, player)
end
end
I put my modified code into function to shorten the script.
local function TeleportPlayers(GameID)
if GameID == gameID1 then
for _, player in pairs(playerList) do
TeleportService:Teleport(gameID1, player)
end
elseif GameID == gameID2 then
for _, player in pairs(playerList) do
TeleportService:Teleport(gameID2, player)
end
elseif GameID == gameID3 then
for _, player in pairs(playerList) do
TeleportService:Teleport(gameID3, player)
end
end
end
if mapName == "Celestial by Xepharim" then
print("mapa celestial")
TeleportPlayers(gameID1)
elseif mapName == "Circuit Board" then
print("mapa circuit")
TeleportPlayers(gameID2)
elseif mapName == "The Oil Rig by PetitePYT" then
print("mapa oil rig")
TeleportPlayers(gameID3)
end
end
I would store the game IDs like this so you don’t have to have a massive if/elseif statement to select the map. Just make sure you type in the name as I’ve done here for the correct IDs. I assumed the IDs were in order of the if statement.
local Players = game:GetService("Players")
local playerList = Players:GetPlayers()
-- Teleports
local TeleportService = game:GetService("TeleportService")
local gameIDs = {
["Celestial by Xepharim"] = 6328942781,
["Circuit Board"] = 6328942781,
["The Oil Rig by PetitePYT"] = 6328942781
}
for _,player in pairs(game.Players:GetPlayers()) do
TeleportService:Teleport(gameIDs[mapName], player)
end
for i,v in pairs(game.Players:GetPlayers()) do
end
The for i,v in pairs loop goes through all of the desired things it’s supposed intended to (In this case, we’re getting all the Players in this loop)
The i variable I believe is what the index of the loop is supposed to be 1, 2, 3, etc (Or what’s meant to be on a table)
And the v variable is the value of the loop, or what Instance it’s getting (Some examples in relevance to what the index is defined as):
(The specific index will be equal to that value if I’m correct)
1 = Backpack
2 = StarterGear
3 = PlayerScripts
4 = RandomBoolValue (That we parented to on the player for whatever reason)
5 = NumberValue (I’m running out of ideas)
So if we were to print this out:
for i,v in pairs(game.Players:GetPlayers()) do
print(i, v)
end
We should get an Output of the Index, and the Value of all the players or in this case: