BodyPosition's Position attribute is always 0,0,0?

Hello, I’m trying to make a sphere part that sort of acts like a curve when it’s going to it’s target, using BodyPosition. It’s working well so far, except for the fact that the bodypostion’s poisition is always 0,0,0 even though I’m setting it to something else:

Screenshot_44

local backpart = workspace.Part
local target;
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        target = character:FindFirstChild("HumanoidRootPart")
    end)
end)

repeat wait() until target

while wait() do
    -- print('x') -- prints
    local mag_from_backpart = (backpart.Position - script.Parent.ball.Position).Magnitude
    local mag_from_target = (target.Position - script.Parent.ball.Position).Magnitude
    
    if mag_from_backpart <= 5 then
        script.Parent.BodyPosition.Position = Vector3.new(target.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
    elseif mag_from_target <= 5 then
        script.Parent.BodyPosition.Position = Vector3.new(backpart.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
    else
        script.Parent.BodyPosition.Position = Vector3.new(target.CFrame:VectorToObjectSpace(script.Parent.ball.Position))
    end
    
end

It would also be helpful if someone could direct me to another resource for accomplishing this, because this method doesn’t seem very useful and it feels hard to script. Thank you :slight_smile:

This problem may arise when the part is anchored. Did you double check to make sure it is not anchored?

Yeah the part is not anchored, but it still moves to 0,0,0

Are there any errors in Output?

What is your logic behind this?

target.CFrame:VectorToObjectSpace(script.Parent.ball.Position)

This is already a Vector3. You don’t need a Vector3.new infront

VectorToObjectSpace is an orientation transformation. Used for getting relative direction. Are you sure this is what you want?

I don’t know what you’re going to do with this script but here I fixed it

local Players = game:GetService("Players")

local backpart = workspace:FindFirstChild("Part")
local ball = workspace:FindFirstChild("ball")

local target

local function onCharacterAdded(character)
	target = character:FindFirstChild("HumanoidRootPart")
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)

while wait() do
	if target then 
		local mag_from_backpart = (backpart.Position - ball.Position).Magnitude
		local mag_from_target = (target.Position - ball.Position).Magnitude

		if mag_from_backpart <= 5 then
			ball.BodyPosition.Position = target.Position
		elseif mag_from_target <= 5 then
			ball.BodyPosition.Position = ball.Position
		else
			ball.BodyPosition.Position = target.Position
		end		
	end
end