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