✓ Accepted answer
Relative, you say? The answer is lookvector.
CFrame roblox documentation
If you dont know, its part of CFrame. CFrame is a property ALL "BaseParts" have. CFrame is just physical data like Location and ROtation and stuff. The humanoidrootpart is a type basepart. So if you wanted to summon a part in front of the player 5 studs away, code would look like this.
local hrp = plr:Waitforchild"HumanoidRootPart"
local originCFrame = hrp.CFrame
local newCFrame = originCFrame * CFrame.new(originCFrame.LookVector *5)
[insert part you wish to summon, here].CFrame = newCFrame
I am using "* CFramew.new()" here to add it. multiplying CFrames just adds them, I dont know why its multiplication, i forgot since its not useful information to me. And FYI using only one paremeter (a Vector3 type) when making a CFrame.new() makes a new cframe thats basically empty except for location values such as X,Y, and Z. Also, the LookVector is a Vector3 which is an X,Y, and Z only. To explain a Lookvector now, All look vector is, is the RELATIVE position exactly 1 stud away in that direction of whatever part the cframe belongs to. So hrp.CFrame.Lookvector i believe gets the position thats a stud away in FRONT of humanoidrootpart. SO all you gotta do is multiply that by 5 and its 5 studs in front of humanoidrootpart. Also, the reason multiplying this by 5 works and doesnt offset everything by 5 times the normal amount and ruin it is because its a relative position MEANING the Vector3 treats the humanoidrootpart as the origin (0, 0, 0) instead of the worlds origin of (0, 0, 0), So this isnt the actual world origin, its just the RELATIVE origin here. Its not a world position at this point. So multiplying by 5 makes does multiply it all by 5 but just relative to humanoidrootpart, meaning all it does is end up on a point thats 5 studs away thats in the same direction the original lookvector is away from the humanoidrootpart origin instead of away from the world origin. And it adds that to the humanoidrootpart's cframe by translating it to world position auTomAtiCAllY.
And if you dont like cframe. here is the version without extra cframe usage, so it doesnt care about rotation or anyhting, only Position.
local hrp = plr:Waitforchild"HumanoidRootPart"
local newPos = hrp.Position + (hrp.CFrame.LookVector *5)
[insert part you wish to summon, here].Position = newPos
Hope this helps.
3 comments
nevermind its wrong LOL
the X is relative to the player
wdym by that?