Portal Gun teleporters orientation not working properly

Hey!

I’m making a portal gun in ROBLOX (for a video!) but I’m having some complications with it. Whenever I shoot, I want the teleporters to have the same orientation as the wall they’re hitting. As you can see in the picture, you’ll notice the problem soon enough. Does anyone know a solution for this? I tried lookvector and faces & just changing the orientation but it sometimes doesn’t work. I have a feeling it has to do with the wall placement but that would be a hell to fix (if viewers are watching it!).

But sometimes it does work…

Here’s the code you’ll need.
The .Touched event is where your attention needs to be :slight_smile:

When you click, a ball will shoot. When the ball hits a surface it’ll place a teleporter there. I just need help with the teleporters orientation!

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent", 60)
local Count = 0

RemoteEvent.OnServerEvent:Connect(function(Player, Velocity, Pos)
	if not Player then return end
	if Count == 0 then
		Count += 1
		for i, v in pairs(workspace["PortalGunFolder"..Player.Name]:GetChildren()) do
			if v then
				v:Destroy()
			end
		end
		local BlueProjectile = ReplicatedStorage.PortalStorage.BlueProjectile:Clone()
		BlueProjectile.Player.Value = Player.Name
		BlueProjectile.CFV.Value = Pos
		
		local BodyForce = Instance.new("BodyForce")
		BodyForce.Parent = BlueProjectile	
		BodyForce.Force = Vector3.new(0, BlueProjectile:GetMass() * 196.2, 0)
		
		Debris:AddItem(BlueProjectile, 10)
		
		BlueProjectile.Parent = workspace["PortalGunFolder"..Player.Name]
		BlueProjectile.Anchored = false
		BlueProjectile.CFrame = script.Parent.Handle.CFrame
		
		BlueProjectile.Velocity = Velocity * 2
		
		BlueProjectile.Touched:Connect(function(Object)
			if Object:IsA("Part") then
				if not Players:GetPlayerFromCharacter(Object.Parent) then
					BlueProjectile.Transparency = 1
					local Part = Object
					local Clone = ReplicatedStorage.PortalStorage.BluePortal:Clone()
					Clone.Parent = workspace:FindFirstChild("PortalGunFolder"..BlueProjectile.Player.Value)
					Clone.Position = BlueProjectile.CFV.Value
					Clone.Name = "BluePortal"..BlueProjectile.Player.Value
					Clone.Orientation = Part.Orientation
					if Part.Size.X > Part.Size.Y then
						Clone.Orientation += Vector3.new(90, 0, 0)
					end
					BlueProjectile:Destroy()
				end
			end
		end)
	elseif Count == 1 then
		Count = 0
		local OrangeProjectile = ReplicatedStorage.PortalStorage.OrangeProjectile:Clone()
		OrangeProjectile.Player.Value = Player.Name
		OrangeProjectile.CFV.Value = Pos

		local BodyForce = Instance.new("BodyForce")
		BodyForce.Parent = OrangeProjectile	
		BodyForce.Force = Vector3.new(0, OrangeProjectile:GetMass() * 196.2, 0)

		Debris:AddItem(OrangeProjectile, 10)
		
		OrangeProjectile.Parent = workspace["PortalGunFolder"..Player.Name]
		OrangeProjectile.Anchored = false
		OrangeProjectile.CFrame = script.Parent.Handle.CFrame
		
		OrangeProjectile.Velocity = Velocity * 2
		
		OrangeProjectile.Touched:Connect(function(Object)
			if Object:IsA("Part") then
				if not Players:GetPlayerFromCharacter(Object.Parent) then
					OrangeProjectile.Transparency = 1
					local Part = Object
					local Clone = ReplicatedStorage.PortalStorage.OrangePortal:Clone()
					Clone.Parent = workspace:FindFirstChild("PortalGunFolder"..OrangeProjectile.Player.Value)
					Clone.Position = OrangeProjectile.CFV.Value
					Clone.Name = "OrangePortal"..OrangeProjectile.Player.Value
					Clone.Orientation = Part.Orientation
					if Part.Size.X > Part.Size.Y then
						Clone.Orientation += Vector3.new(90, 0, 0)
					end
					OrangeProjectile:Destroy()
				end
			end
		end)
	end
end)

Thank you so much!

I have tried doing Part1.CFrame = CFrame.new(Part1.Position) * Part2.CFrame.Rotation
But that ruins it on the ground.


You should use the surface’s normal to gave the right orientation