Teleportation Service not working and not giving any errors

Hello developers, my teleport function won’t work when I call it, I’ve tried many solution but it won’t work…and it didn’t give out any errors

local RS = game:GetService("ReplicatedStorage")
local TeleportEVent = RS:WaitForChild("TeleportPlace")
local TeleportService = game:GetService("TeleportService")
local placeId = 9074128788

local teleporting = false

local list = {}

local function teleportPlayers(hit)
	if #list > 0 then
		local playersToTeleport = {}
		local teleportTime = 0
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end 
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if Player then

		local code = TeleportService:ReserveServer(placeId)
		teleporting = true
		TeleportService:TeleportToPrivateServer(placeId,code,playersToTeleport)
		repeat wait() until #list <= 0
			teleporting = false
		end
	end
end

--[[function onTouched(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
			
	end
end]]--

script.Parent.Touched:Connect(teleportPlayers)

Thank you for your help!

I’m pretty positive that :findFirstChild is depracated and doesn’t work as intended anymore. It’s now :FindFirstChild. This might be the issue honestly but very unlikely.

Also just do,

local Player = game.Players:FindFirstChild(hit.Parent.Name)
--// instead of
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

No, I don’t think it’s that, could it be this part of the script that I need to delete because it seems irrelevant

Quick question; Are you adding all of the players to the “list” table if so, where?

Ooh, that’s probably why, let me see if I can add it

Because from what I’m seeing is nowhere is there anyone being added into the list table but you are trying to get all the players from the list table. Could just be me not seeing something right infront of my face.

1 Like

So I did fix the script up a little bit but I got this error, I heard that it will go away when I test it on the actual Roblox but I did and it didn’t teleport me nor did it give me any errors…

local RS = game:GetService("ReplicatedStorage")
local TeleportEVent = RS:WaitForChild("TeleportPlace")
local TeleportService = game:GetService("TeleportService")
local placeId = 9074128788

local teleporting = false

local list = {}

local function removeFromList(character)
	for i=1,#list do
		if list[i] == character.Name then
			table.remove(list,i)
		end
	end
end

local function teleportPlayers(hit)
	if #list > 0 then
		local playersToTeleport = {}
		for i=1,#list do
			if game.Players:findFirstChild(list[i]) then
				table.insert(playersToTeleport,game.Players:FindFirstChild(list[i]))
			else
				table.remove(list,i)	
			end
		end
		local code = TeleportService:ReserveServer(placeId)
		teleporting = true
		TeleportService:TeleportToPrivateServer(placeId,code)
		repeat wait() until #list <= 0
			teleporting = false
end
end

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false

			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end

			if alreadyExists == false then
				if #list < 2 then -- Many Players have been teleported.
					table.insert(list,char.Name)
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end

		end
	end
	teleportPlayers()
end)
--[[function onTouched(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
			
	end
end]]--

--script.Parent.Touched:Connect(teleportPlayers)

Line 61: You are failing to pass through hit

It’s also not inside of the if then if you want it to be inside of there move it above the end right above it

How would I come to fix that? Sorry it’s kind of confusing for me

It also said at the picture that I put something on line 28

change it to the following

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:findFirstChild("Humanoid") then
		if teleporting == false then
			local char = hit.Parent
			local player = game.Players:FindFirstChild(char.Name)
			local alreadyExists = false

			for i=1,#list do
				if list[i] == char.Name then
					alreadyExists = true
				end
			end

			if alreadyExists == false then
				if #list < 2 then -- Many Players have been teleported.
					table.insert(list,char.Name)
				end

				player.CharacterRemoving:connect(function(character)
					removeFromList(character)
				end)
			end

		end
       teleportPlayers(hit)
	end
end)

Hm, it’s still not working for some reason, it also didn’t give any errors…

Oops! Nevermind that, I gotta add something else from the script that I accidentally deleted, thank you so much again for your help

For sure my man, let me know if something else goes wrong

1 Like