Can't set the part position

I’m trying to set the part between PartA and PartB. The code looks like this

However, I ran into an issue and I don’t understand what it means

Can someone help me solve this? I really don’t understand what the issues here.

2 Likes

Untested and may be flawed logic, but:
try replacing the

local Distance = ...

bit with

local Distance = (CubeA.Position + CubeB.Position) / 2
2 Likes

as the error says Distance is a number not a Vector3. Magnitude returns a number representing the length of the vector from point A and point B, or to put it more simply the distance between the 2 points in studs.

in order to set the the position to the halfway point you just have to delete .Magnitude

local Distance = (CubeA.Position + CubeB.Position)  /  2
3 Likes

It would work. But is it possible if I do it using magnitude?

2 Likes

I don’t understand your question. Why do you wish to use magnitude specifically?

I suppose if you really wanted to use magnitude you could do

local Magnitude = (CubeA.Position + CubeB.Position).Magnitude / 2
local Distance = CFrame.lookAt(CubeA.Position, CubeB.Position).LookVector * Magnitude 

LookVector represents a unitVector(meaning a 1 stud long vector) and Magnitude would give as a distance that is half as long as the distance between the 2 Cubes, thus by multiplying the lookvector with magnitude we would get the same position as we did with the above code

2 Likes

I want to use the magnitude value as a position so I can give that value to WhiteCube position. I wanna know if it’s possible using magnitude

2 Likes

magnitude is a number so you can’t use it to set the position which is Vector3

2 Likes

Oh I think I kinda understand now. Thanks for the replies.

if one of my replies is the answer to your question please mark it as solved so that others who have the same question can quickly find the answer without reading through everything

1 Like

So it only works if you use CFrame.new?

1 Like

Yes if you want to use magnitude the only way i can think of is that you get the lookvector and multiply it with magnitude

1 Like

I tried it and it doesn’t work with the magnitude. The cube doesn’t locate at the middle when I tested it.

1 Like
local PointA = -- Cube A Position
local PointB = -- Cube B Position
local Mid = PointA:Lerp(PointB,0.5) -- What you want and should set.
while true do
	local midPos = (CubeA.Position + CubeB.Position)/2
	task.wait()
	WhiteCube.Position = midPos
end

This one can also work but I’m trying to find the alternative way using magnitude.

may i ask why you’re so obsessed with magnitude? there’s nothing special or particularly practical about using it?

I think I already did it. I tried so many attempts to make my own code but I think I made it works. Thanks for your time.