Part Position Issue

Here’s the code:

This code makes “movingpart” constantly move up and down on the Y axis.

Here’s the error:

What does this error mean and how do I fix it?

You can’t change the values of a vector3, instead you have to create a new vector3.

local movingpart = script.Parent
while true do
    for a = 1, 10, .01 do
        task.wait(.01)
        movingpart.Position = Vector3.new(movingpart.Position.X, movingpart.Position.Y + .01, movingpart.Position.Z)
    end
    
    for a = 1, 10, .01 do
        task.wait(.01)
        movingpart.Position = Vector3.new(movingpart.Position.X, movingpart.Position.Y - .01, movingpart.Position.Z)
    end
end
1 Like

Or for a smooth movement, you could use tweens.

local tweenService = game:GetService("TweenService")
local movingpart = script.Parent
local offset = Vector3.new(0, 5, 0)
local originalCFrame = movingpart.CFrame

while task.wait() do
    local upTween = tweenService:Create(movingpart, TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {
        CFrame = (originalCFrame + offset)
    })
    
    upTween:Play(); upTween.Completed:Wait()
    upTween:Destroy()
    
    local downTween = tweenService:Create(movingpart, TweenInfo.new(1.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {
        CFrame = (originalCFrame)
    })

    downTween:Play(); downTween.Completed:Wait()
    downTween:Destroy()
end