Teleporting player glitches it in the map

Hello Developers, so in my free time i was building a map, i decided to add a portal to teleport the player to a different zone. To teleport a player i always define the torso, and then move the torso with Vector3
Example:

script.Parent.Touched:Connect(function(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	local Torso = Humanoid.Torso
	if Torso then
		Torso.Position = Vector3.new(0,0,0) -- For example
     end
end)

I added a kind of transition, a simple one. I used a loop to add transparency to a frame.
Example:

local player = game:GetService("Players").LocalPlayer
local part = game.Workspace.Portal.Teleport

part.Touched:Connect(function(hit)
	if hit.Parent == player.Character then
		script.Parent.Visible = true
		player.Character.HumanoidRootPart.Position = Vector3.new(-63.456, 58.586, 109.709)
		for i = 1,20 do
			wait(0.1)
			script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency +0.1
			
		end
	end
end)

Here a video of what happens:

So the transition works, to record the video i just removed it, but the player glitches in the map, is there a way to move a player without glitching it?

Thanks for reading.

  1. Anchor the player and set to cancollide false (if you have lerp, etc)
  2. Add debounce
  3. Instead of transitioning the transparency that way, use tweenservice.
local player = game:GetService("Players").LocalPlayer
local part = game.Workspace.Portal.Teleport
Debounce = false
part.Touched:Connect(function(hit)
	if hit.Parent == player.Character and Debounce ~= true then
Debounce = true
		script.Parent.Visible = true
		player.Character.HumanoidRootPart.Position = Vector3.new(-63.456, 58.586, 109.709)
		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {BackgroundTransparency = 1}):Play((
wait(1)
Debounce = false
	end
end)
1 Like

Use CFrame instead of Position, and use HumanoidRootPart instead of Torso.

1 Like

Thanks i will definetly try that

Use this when setting the position of the player.

player.Character:SetPrimaryPartCFrame(CFrame.new(-63.456, 58.586, 109.709))

1 Like

Since the player character is a Model, you can use Model:MoveTo([pos]) which move all of the parts to a location, it also makes sure that they don’t get stuck inside other parts.

1 Like

So i solved it, thanks @Winbloo and @GummyScript , i couldn’t find the issue, but i changed

player.Character.HumanoidRootPart.Position = Vector3.new(-63.456, 58.586, 109.709)

to

player.Character:SetPrimaryPartCFrame(CFrame.new(-63.456, 58.586, 109.709))

and it worked perfectly. :woot:

1 Like