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

Make a part that links two points?

This is what I currently have

part.CanCollide = false
		part.Name = "Ray"
		part.Anchored = true
		part.BrickColor = BrickColor.new("Crimson")
		part.Transparency = .4
		part.Size = Vector3.new((mob.Head.Position - 	centerOfTheMap.Position).magnitude,.2,.2)
		part.Position = ((mob.Head.Position+centerOfTheMap.Position)/2)

		part.Parent = workspace

But I don't quite grasp how CFrame works and I can't seem able to make the part go through two point's in space.

2 answers

Working with CFrame is a lot like working with Part.Position, though there is a difference. Whenever you change a Part's position or rotation in space, you should use CFrame, not Part.Position. Using Part.Position can create unwanted and unexpected effects. It is quite simple, actually:

part.CanCollide = false
part.Name = "Ray" --Note, of course, that you don't have to indent
part.Anchored = true
part.BrickColor = BrickColor.new("Crimson")
part.Transparency = .4
part.Size = Vector3.new((mob.Head.Position -    centerOfTheMap.Position).magnitude,.2,.2)
part.CFrame = CFrame.new((mob.Head.Position+centerOfTheMap.Position)/2) --Instead of position, with Vector3.new, use CFrame, with CFrame.new
part.Parent = workspace

This is the Wiki page for CFrames, since there is lots more that you can do with it: http://wiki.roblox.com/index.php?title=CFrame

2 comments

0

Doesn't work, the part doesn't connect the two points but goes horizontally between them.

0

What exactly are you trying to do here? Do you mean you want to resize a part so it is bridging two points in space?

To create a part between two points:

--create the points
local pos1 = Vector3.new()
local pos2 = Vector3.new(10,10,10)
--get information
local diff = pos2-pos1
local dist = diff.magnitude
local center = pos2 - (diff/2)
--create the part
local part = Instance.new('Part',workspace)
part.Anchored=true
--simple
part.Size = Vector3.new(1,1,dist)
--first argument is position, second argument is what to look at...
part.CFrame = CFrame.new(center,pos2)

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