Game teleporting script not working

Hello. I’m AwesomeAgent404 and I am trying to make a game teleporter but every time I try to test the game I get this error

I have tried two methods for a game teleporter that I found a tutorial for and both of them don’t work. I don’t know what else to do
here is the script I currently have

local GameID = "15626477334" -- paste your game id in the bracket

script.Parent.Touched:Connect(function(Player)
	local FromCharacter = game.Players:GetPlayerFromCharacter(Player.Parent) -- make sure that the player who touched the part is a player
	if FromCharacter then 
		local TeleportService = game:GetService("TeleportService") -- teleport service
		TeleportService:Teleport(GameID,FromCharacter) -- if true then teleport the player to the game
	end
end)
1 Like

A few things, the first parameter of the TeleportService:Teleport() function accepts is an integer, not a string. You’re supplying it with a string in GameID.

Secondarily, your Touched event is spammed with the smallest of character movement while in contact with the BasePart. You can counter this with a short debounce/cooldown to provide enough time for the teleport to process.

Slightly cleaned up your code alongside:

-- ServerScript

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")

local GameID = 15626477334 -- paste your game id in the bracket
local dbs = {}

script.Parent.Touched:Connect(function(Hit)
	local Player = Players:GetPlayerFromCharacter(Hit.Parent) -- make sure that the player who touched the part is a player
	
	if Player and not dbs[Player] then
		dbs[Player] = true
		
		TeleportService:Teleport(tonumber(GameID), Player) -- if true then teleport the player to the game
		
		task.wait(5)
		dbs[Player] = false
	end
end)
2 Likes

so the script itself works great :smiley: but for some reason, the game I was originally teleporting to isn’t loading not even if I open it by itself.

Use This Script! Numbers is game id.

script.Parent.Touched:Connect(function(hit)
	game:GetService("TeleportService"):Teleport(7449491602,game.Players[hit.Parent.Name])
end)