Greetings
I need little bit help. I am trying to create easy and simple script, which can let players to join random games by their id. I tried to use min and max for GameIDs. I also tried everything and ran out of my ideas how to fix my script.
My script:
local function getRandomGameId(minId, maxId)
return math.random(minId, maxId)
end
local function TeleportPlayerToGame(player, gameId)
local success, errorMessage = pcall(function()
local teleportService = game:GetService("TeleportService")
local gameInfo = teleportService:GetGameInfo(gameId)
if gameInfo and gameInfo.GameState == Enum.GameInstanceState.Started then
local success, teleportErrorMessage = teleportService:TeleportToPlaceInstance(gameId, "", player)
if not success then
warn("Teleport failed: " .. teleportErrorMessage)
end
else
warn("Game is not playable.")
end
end)
if not success then
warn("Error while teleporting: " .. errorMessage)
end
end
local interactableObject = script.Parent
interactableObject.Touched:Connect(function(otherPart)
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player then
local minGameId = 100
local maxGameId = 232424
local randomGameId = getRandomGameId(minGameId, maxGameId)
TeleportPlayerToGame(player, randomGameId)
end
end)
Output: Error while teleporting: GetGamePlaceInfo is not a valid member of TeleportService “Teleport Service”
Maybe for someone It can looks like as easy problem which can be easily fixed, but I am just blind and I don’t know how.
I will appreciate any help and your advice, thank you very much in advance!