Character TP Won't Work

I scripted a local teleport when you touch a block, it does everything it’s supposed to do other than well… teleport you, I guess.

Code:

game.Workspace.OutOfBodyTeleport.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name then
		char.HumanoidRootPart.CFrame = game.Workspace.UnnamedPositionTeleport.CFrame
		game.Workspace.OutOfBodyTeleport.CanTouch = false
		local clone = game.ReplicatedStorage.BlackScreen:Clone()
		clone.Parent = plr.PlayerGui
		wait(2)
		clone:Destroy()
	end
end)

It used to be this: (Btw this one was working but just randomly stopped working)

game.Workspace.OutOfBodyTeleport.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name then
		game.Workspace.OutOfBodyTeleport.CanTouch = false
		local clone = game.ReplicatedStorage.BlackScreen:Clone()
        char:SetPrimaryPartCFrame(game.Workspace.UnnamedPositionTeleport.CFrame)
		clone.Parent = plr.PlayerGui
		wait(2)
		clone:Destroy()
	end
end)
```

at the old one Just change SetPrimaryPartCFrame to PivotTo and that should work

1 Like

I switched it and it was working, but now it just stopped working again

can i see your new old code then?

game.Workspace.OutOfBodyTeleport.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name then
		char.PrimaryPart:PivotTo(game.Workspace.UnnamedPositionTeleport.CFrame)
		game.Workspace.OutOfBodyTeleport.CanTouch = false
		local clone = game.ReplicatedStorage.BlackScreen:Clone()
		clone.Parent = plr.PlayerGui
		wait(2)
		clone:Destroy()
	end
end)

Use, “:GetPivot()”" for game.Workspace.UnnamedPositionTeleport.

I made a teleport module a while back that’s open-source. Might be worth reading the source code.

Easy enough to use, just insert into your game and read the README.

local Players = game:GetService('Players');
local Player = assert(Players.LocalPlayer);

local character:Model

if Player.Character == nil then
	character = Player.CharacterAdded:Wait();
else
	character = Player.Character;
end;

local outOfBody = workspace.OutOfBodyTeleport;
local unnamedPosition = workspace.UnnamedPositionTeleport;

local showBlackScreen = function()
	local screen = game:GetService('ReplicatedStorage').BlackScreen:Clone();
	screen.Parent = Player.PlayerGui;
	task.wait(2);
	screen:Destroy();
end;

local teleport = function(hitPart:BasePart)
	if Players:GetPlayerFromCharacter(hitPart.Parent) == Player then
		outOfBody.CanTouch = false;
		character:PivotTo(unnamedPosition.CFrame);
		showBlackScreen();
	end;
end;

outOfBody.Touched:Connect(teleport);
1 Like

that is what i suggested but they said it broke