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