Creating a part relative to another

I have a player room folder that is duplicated various times throughout my game. In the past, I had a part placed in the front of the player’s room to signify where the player who owns that room should spawn. However, I would like to calculate this position rather than having a part in the front. Currently, I figured out how to calculate if the room’s orientation is 180, 90, -90, or -180. However, I need to be able to calculate the position at any orientation.

The following is my current code:

local region = workspace.Rooms.Room2.region
local barrier = workspace.Rooms.Room2.barrier
local part = Instance.new("Part",workspace)
part.Size = Vector3.new(1,1,1)
part.Color = Color3.fromRGB(255,0,0)
part.Name = "teleport"
	
local frontVector = (Vector3.new(barrier.Position.X,0,barrier.Position.Z) - Vector3.new(region.Position.X,0,region.Position.Z)).Unit
	
if frontVector.X == 1 then
	frontVector = Vector3.new(40,-3.5,0)
elseif frontVector.X == -1 then
	frontVector = Vector3.new(-40,-3.5,0)
elseif frontVector.Z == 1 then
	frontVector = Vector3.new(0,-3.5,40)
elseif frontVector.Z == -1 then
	frontVector = Vector3.new(0,-3.5,-40)
else
	print("uh oh..",frontVector)
end
	
part.CFrame = region.CFrame + frontVector

The part needs to be 40 towards the front from the center of the room and then down 3.5 studs. Any help is much appreciated, sorry if my code is stupid in advance this is beyond my understanding.

Never mind, despite trying to research solutions beforehand, I just now found [this post].

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.