Teleport players without touching part

So I use this script

function teleportPlayers(partCFrame)
	local players = game.Players:getPlayers()
	for _,player in pairs(players) do
		if player.Character then
			if player.Character.HumanoidRootPart.Anchored == false then
				player.Character.Humanoid.Jump = true
			end
		end
	end
	wait(.5)
	for _,player in pairs(players) do
		if player.Character then
			if player.Character.HumanoidRootPart.Anchored == false then
				player.Character:SetPrimaryPartCFrame(partCFrame)
			end
		end
	end
end

but sometimes, some players didnt get teleported.
Can you help me fixing the code, or maybe redo the code?
Thanks!

i’m not good at coding when it comes to a non-ui but when i want to make a teleport script, i make it like this

function teleportPlayers()
	local players = game.Players:getPlayers()
	for _,player in pairs(players) do
		if player.Character then
			player.Character.HumanoidRootPart.Position = -- Position you want to teleport them
		end
	end
end
1 Like

You should use MoveTo():

function teleportPlayers(partCFrame)
	local players = game.Players:getPlayers()
	for _,player in pairs(players) do
		if player.Character then
if player.Character.HumanoidRootPart.Anchored == false then
				player.Character.Humanoid.Jump = true
			end
if player.Character.HumanoidRootPart.Anchored == false then
				player.Character.Humanoid.Jump = true
			end
		end
	end
end
1 Like

Thank you, I will try both of your code!

local function TeleportPlayers(ObjectCFrame)
	local TimeDelation = 0.5
	for _, Player in ipairs(game.Players:GetPlayers()) do
		if Player.Character then

			Player.Character.Humanoid.Jump = true

			spawn(function()
				wait(TimeDelation)
				Player.Character:SetPrimaryPartCFrame(ObjectCFrame)
			end)
			
		end
	end
	wait(TimeDelation)
	print("All Players Are Teleported")
end

-- Calling The Function (This is justa example on how should you call the function)
wait(4) 
--//--
local Object = game.Workspace.Part
TeleportPlayers(Object.CFrame)

make sure that you call the function properly

1 Like

Thank you so much, this is the best out of all, thank you so much!

local Players = game:GetService("Players")
local Run = game:GetService("RunService")

local function TeleportPlayersToPivot(Object)
	for _, Player in ipairs(Players:GetPlayers()) do
		local Character = Player.Character
		if Character then
			local Humanoid = Character:FindFirstChildOfClass("Humanoid")
			if Humanoid then
				if Humanoid.Health > 0 then
					Humanoid.Jump = true
				end
			end
		end
		
		task.spawn(function()
			Run.Stepped:Wait()
			Character:PivotTo(Object:GetPivot())
		end)
	end
end

You should probably be using pivots, there’s also a few additional improvements you could have made.