Pcall returns false on TeleportService

So I have this script:

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

script.Parent.Touched:Connect(function(part)
	if part.Name ~= "HumanoidRootPart" then return end
	local player = players:GetPlayerFromCharacter(part.Parent)
	if player == nil then return end
	
	local success, message = pcall(teleportService:TeleportAsync(16004814573, {player}))
	
	if success == false then print("False") return end
	
	game.ReplicatedStorage.Teleporting:FireClient(player)
end)

I have a touching part that teleports me when touched. Whenever I touch it wraps the response in a pcall. For some reason it returns false indicating that I won’t be teleported. However after around 4 seconds I do get teleported. You can see that I have a remote event that must be fired right after the pcall but it WON’T be fired because of that if statement that checks the response from the pcall. Appreciating any possible solution.

pcall accepts a function as the first argument and then the values, success returns false since TeleportService:TeleportAsync(16004814573) returns nil, so it cannot call a function

Change it to this:

local success, message = pcall(teleportService.TeleportAsync, teleportService, 16004814573, {player})
1 Like

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