Help with spawning portals in a random wall-like position behind the player

Whenever the player clicks, portals spawns in a wall like pattern behind them

The only problem being that the walls only spawn correctly when the player is facing a certain direction
VVV when the player faces the right direction VVV
image

VVV when the player faces the wrong direction VVV

How do I get the portals to appear just like in the first picture no matter what direction the player is facing

the current code

	NewGate:SetPrimaryPartCFrame((Character.HumanoidRootPart.CFrame + Vector3.new(math.random(-10, 10), math.random(4, 8),0)))

try this:

local behind = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,10) -- a point directly 10 studs behind player
local gateCFrame = behind * CFrame.new(math.random(-10,10),math.random(4,8),0) -- 10 studs either left or right to the character, 4-8 studs upwards
NewGate:SetPrimaryPartCFrame(gateCFrame)

Adjust the value to your liking.

Works perfectly, thank you so much!!!

1 Like