Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

positioning a part a certain amount of studs in front of another parts lookvector?

local part = Instance.new("Part")

part.Parent = game.Workspace

part.Anchored = true

part.CFrame = CFrame.new(script.Parent.CFrame.LookVector * 5)

I wanted to change a parts position a certain distance from another parts LookVector, so I Created a test script to see if what I had in mind would work. it did not work and no error came up. can someone show me the correct way to do this?

1 answer

LookVector * 5 + Vector3.new(#,#,#) will add the number onto the position

6 comments

0

local part = Instance.new("Part") part.Parent = game.Workspace part.Anchored = true part.CFrame = CFrame.new(script.Parent.CFrame.LookVector * 5 + Vector3.new(0,0,-3)) is this what you mean?

0

exacly

0

the part only spawns in the same spot at the center of the workspace.

0

are you sure about that because this is how it went for me, this is without the vector3 https://imgur.com/a/8Z41bBN and https://imgur.com/a/qYv4JpS this is how it went with vector3 https://imgur.com/a/jRHtyvn and https://imgur.com/a/hWvpxep

0

after looking over your results the position was in fact the same as yours, but its still relativly in the center of the workspace. I tried playing around with the values and moved "script.Parent" in different positions but the new part always goes to the world center. im just trying to get the new part to spawn maybe 5 studs in front of "script.Parent"

0

I finally found a solution. we were both doing it wrong: local part = Instance.new("Part") print(part.Name) part.Parent = game.Workspace part.Anchored = true part.Position = script.Parent.Position + script.Parent.CFrame.LookVector * 3 print(part.Position)

This discussion is preserved as it was. New answers, comments, and votes are closed.