Im getting this error.
This script is from gnomecode and its a tower defense simulator elevator. It teleports players after a certain amount of time standing in them.
Script:
local elevator = script.Parent
local safeteleport = require(game.ServerScriptService.SafeTeleport)
local primastic = script.Parent.Shaft.PrismaticConstraint
local players = game:GetService('Players')
local replicatedstorage = game:GetService('ReplicatedStorage')
local teleportservice = game:GetService('TeleportService')
local elevatorevent = replicatedstorage:WaitForChild('Elevator')
local countdownRunning = false
local moving = false
local playerswaiting = {}
local gui = elevator.Platform.SurfaceGui.Frame
local config = elevator.Configuration
local function setup()
playerswaiting = {}
local moving = false
gui.PlayerCount.Text = #playerswaiting.. ' / '.. config.MaxPlayers.Value
gui.Status.Text = ''
end
local function teleportplayers()
local placeid = 11846983309
local server = teleportservice:ReserveServer(placeid)
local options = Instance.new('TeleportOptions')
options.ReservedServerAccessCode = server
safeteleport(placeid, playerswaiting, options)
end
local function MoveElevator()
local moving = true
for i, player in pairs(playerswaiting) do
replicatedstorage.MovingElevator:FireClient(player)
end
gui.Status.Text = 'Teleporting'
primastic.TargetPosition = -30
task.wait(10)
primastic.TargetPosition = 0
task.wait(8)
setup()
end
local function RunCountdown()
countdownRunning = true
for i=10,1,-1 do
gui.Status.Text = i
task.wait(1)
if #playerswaiting < 1 then
countdownRunning = false
setup()
return
end
end
MoveElevator()
teleportplayers()
countdownRunning = false
end
elevator.Entrance.Touched:Connect(function(part)
local player = players:GetPlayerFromCharacter(part.Parent)
local isWaiting = table.find(playerswaiting, player)
if player and not isWaiting and #playerswaiting < config.MaxPlayers.Value and not moving then
table.insert(playerswaiting, player)
gui.PlayerCount.Text = #playerswaiting.. ' / '.. config.MaxPlayers.Value
player.Character.PrimaryPart.CFrame = elevator.TeleportIn.CFrame
elevatorevent:FireClient(player, elevator)
if not countdownRunning then
RunCountdown()
end
end
end)
elevatorevent.OnServerEvent:Connect(function(player)
local isWaiting = table.find(playerswaiting, player)
if isWaiting then
table.remove(playerswaiting, isWaiting)
end
gui.PlayerCount.Text = #playerswaiting.. ' / '.. config.MaxPlayers.Value
if player.Character then
player.Character.PrimaryPart.CFrame = elevator.TeleportOut.CFrame
end
end)
Roblox’s teleport script:
local TeleportService = game:GetService("TeleportService")
local ATTEMPT_LIMIT = 5
local RETRY_DELAY = 1
local FLOOD_DELAY = 15
local function SafeTeleport(placeId, players, options)
local attemptIndex = 0
local success, result -- define pcall results outside of loop so results can be reported later on
repeat
success, result = pcall(function()
print('teleporting'.. #players) -- teleport the user in a protected call to prevent erroring
return TeleportService:TeleportAsync(placeId, players, options)
end)
attemptIndex += 1
if not success then
task.wait(RETRY_DELAY)
end
until success or attemptIndex == ATTEMPT_LIMIT -- stop trying to teleport if call was successful, or if retry limit has been reached
if not success then
warn(result) -- print the failure reason to output
end
return success, result
end
local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
if teleportResult == Enum.TeleportResult.Flooded then
task.wait(FLOOD_DELAY)
elseif teleportResult == Enum.TeleportResult.Failure then
task.wait(RETRY_DELAY)
else
-- if the teleport is invalid, report the error instead of retrying
error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
end
SafeTeleport(targetPlaceId, {player}, teleportOptions)
end
TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)
return SafeTeleport
I can’t figure out why this isnt working, so all help is apprieciated!