What does this mean?

I’m trying to make a teleporter so the player can teleport to other games, and it works. It just takes a few seconds and gives me this error:


I don’t really know too much about TeleportService yet, so I could just be overlooking something simple.

You are trying to Teleport the player everytime they touch the blue part, so this means that everytime the player touchs it a teleport is activated while another teleport is already processing.

You can try to add a debounce or cooldown to this.

3 Likes

That’s what I was thinking of doing, but I just wanting to make sure it wasn’t some game-breaking error.

local TeleportService = game:GetService("TeleportService")

local PlaceId = "10547550169"

function onTouch(Player)
	local fromChar = game.Players:GetPlayerFromCharacter(Player.Parent)
	if fromChar then
		TeleportService:Teleport(PlaceId, fromChar)
	end
end

script.Parent.Touched:Connect(onTouch)

Can you pls show me where to implement the debounce?

Do you turn on about can Teleport?

1 Like

If you are using a Server Script and want to make a cooldown for each player you can use a table to store each player cooldown/debounce.

local Debounces = {}

function onTouch(Player)
	local fromChar = game.Players:GetPlayerFromCharacter(Player.Parent)
	if fromChar then
      if Debounces[Player] then return end
         Debounces[Player] = Player
		 TeleportService:Teleport(PlaceId, fromChar)
         wait(10) Debounces[Player] = nil
	end
end
1 Like
local TeleportService = game:GetService("TeleportService")

local PlaceId = "10547550169"
local dbPlayer = {}

function onTouch(Player)
	local fromChar = game.Players:GetPlayerFromCharacter(Player.Parent)
	if fromChar and not dbPlayer[player]  then
                 dbPlayer[player]  = true
		TeleportService:Teleport(PlaceId, fromChar)
                wait(6)
                dbPlayer[player]  = nil
	end
end

script.Parent.Touched:Connect(onTouch)
1 Like

That script looking working , please add “wait” for not let this spam Teleport.

local TeleportService = game:GetService("TeleportService")

local PlaceId = "10547550169"

function onTouch(Player)
	local fromChar = game.Players:GetPlayerFromCharacter(Player.Parent)
	if fromChar then
        wait(2)
		TeleportService:Teleport(PlaceId, fromChar)
	end
end

script.Parent.Touched:Connect(onTouch)
1 Like

The code works, but I’m still getting the error.

I don’t think you should be worry about this, That error that trying to let you Teleport to by placeid :slight_smile:

1 Like

So you’re saying I shouldn’t worry about it? I mean, the teleporters work fine and can successfully teleport the player from one game to another.

Yes :+1:, That error is for saying if on settings game can “Teleport” or not, That should be fine :slight_smile: !

1 Like

All right, then. That makes sense. Thank you very much!

The current solution to the topic isn’t efficient, it will add an unnecessary delay of 2 seconds before teleporting the player, and also not solve the issue if the teleport takes more than 2 seconds to complete.

Here’s a way of teleporting the player by using debounces and handling teleport errors:

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

local placeId = 10547550169
local processing = {} 

function removeDebounce(player: Player)
	local index = table.find(processing, player) 
	if index then table.remove(processing, index) end 
end

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if not player or table.find(processing, player.UserId) then return end
	table.insert(processing, player)
	TeleportService:Teleport(placeId, player)
end)

TeleportService.TeleportInitFailed:Connect(function(player, result, errMessage, id)
	if placeId ~= id then return end 
	removeDebounce(player)
end)

Players.PlayerRemoving:Connect(removeDebounce)

Basically what the code does is that it flags the player as “teleporting” when the game attempts to teleport them and doesn’t let the game do another teleport until this flag is off. If an error occurs and the player isn’t teleported their flag will be removed which will allow the game to teleport them again when they retouch the part/move. The reason the PlayerRemoving connection is there is so when the player gets teleported, or if they leave before the teleport succeeds or errors, they will be removed from the processing array to ensure no memory leaks happen.

1 Like

Hello :wave:, I wrong that script spam about teleport so I been will fixing your script today , Sorry for this! :pray:

1 Like

I fixed this :slight_smile:
Here update script working:

local TeleportService = game:GetService("TeleportService")

local PlaceId = "Your PlaceId"

local teleportwait = {}

function onTouch(Player)
	local fromChar = game.Players:GetPlayerFromCharacter(Player.Parent)
	if fromChar and not teleportwait[fromChar.UserId] then
		teleportwait[fromChar.UserId] = true
		TeleportService:Teleport(PlaceId, fromChar)
		wait(5) -- Don't remove this, if you will do this so that will spam a request Teleport 👍
		teleportwait[fromChar.UserId] = false
	end
end

script.Parent.Touched:Connect(onTouch)

Please say if that have something issue or not working :pray:

1 Like

It works great! Thank you so much for your help! :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.