How would i teleport the player relative to the "front" face of a part?

I have a teleport script in place however it’s not working as i would like it to:

  • It’s teleporting the player in the wrong places
  • Once the player is teleported, he falls down and usually gets moved back to the TP pad teleporting them back where they came from.
local CS = game:GetService("CollectionService")
local Parts = CS:GetTagged("TP")

for i, v in pairs(Parts) do
	v.Touched:Connect(function(hit)
		if game.Players:FindFirstChild(hit.Parent.Name) and not hit.Parent:FindFirstChild("Grabbable") then
			local char = game.Players[hit.Parent.Name].Character
			if v.Parent.Name == "In" then	
				game.ReplicatedStorage.Effect:FireClient(game.Players[hit.Parent.Name], true)
				wait(1)
				hit.Parent:SetPrimaryPartCFrame(CFrame.new(0,8,6):ToWorldSpace(game.Workspace.Structure.Out:FindFirstChild(v.Name).CFrame) * CFrame.Angles(0,0,0))
			else
				game.ReplicatedStorage.Effect:FireClient(game.Players[hit.Parent.Name], true)
				wait(1)
				hit.Parent:SetPrimaryPartCFrame(CFrame.new(0,8,6):ToWorldSpace(game.Workspace.Structure.In:FindFirstChild(v.Name).CFrame) * CFrame.Angles(0,0,0))
			end
		end
	end)
end

I want it to teleport infront of a part, regardless of its orientation.

This is my script, Let me know if it’s wrong. Thanks

CFrame multiplication is not commutative. The dev hub tutorial stated this.

You are multiplying the offset cframe by the part’s cframe, when you should have been multiplying the part’s cframe by the offset cframe.

Replace that code with this code and tell me if it helped:

local CS = game:GetService("CollectionService")
local Parts = CS:GetTagged("TP")

for i, v in pairs(Parts) do
	v.Touched:Connect(function(hit)
		if game.Players:FindFirstChild(hit.Parent.Name) and not hit.Parent:FindFirstChild("Grabbable") then
			local char = game.Players[hit.Parent.Name].Character
			if v.Parent.Name == "In" then	
				game.ReplicatedStorage.Effect:FireClient(game.Players[hit.Parent.Name], true)
				wait(1)
				hit.Parent:SetPrimaryPartCFrame(game.Workspace.Structure.Out:FindFirstChild(v.Name).CFrame:ToWorldSpace(CFrame.new(0,8,-6)))
			else
				game.ReplicatedStorage.Effect:FireClient(game.Players[hit.Parent.Name], true)
				wait(1)
				hit.Parent:SetPrimaryPartCFrame(game.Workspace.Structure.In:FindFirstChild(v.Name).CFrame:ToWorldSpace(CFrame.new(0,8,-6)))
			end
		end
	end)
end

This is, of course, assuming that the offset cframe you chose is correct.

2 Likes

It worked, Thank you!

Also, How would i make it so the character keeps his orientation because this happens:
https://gyazo.com/06f21b4b67bd627b8ca9d6e35d566bbe

The character is being flung because they were teleported into a part. This means that you need to choose another offset cframe, as cframe.new(0,8,-6) teleports them into a part.

I think the Y value you choose (8) is too high and teleports them into the roof. Maybe lower that, and if it still doesn’t work, play around with different values until you find one that works.

Have a nice day! :slightly_smiling_face:

1 Like

It’s not being flung, just before that video when i tested your code, The character was oriented wrong and wans’t touching any parts,

It got flung as a result of the wrong orientation + the forced shift lock.

EDIT: It’s okay now i fixed it, Have a nice day also :smiley:

1 Like