Lift Script Help

I’m writing a script that when a block is clicked, it would add X to a block’s Y position and then move it up X studs. Here’s the script I have now:

local lift = script.Parent.Height --NumberValue

while true do
    script.Parent.Position.Y = script.Parent.Position.Y + lift.Value
    wait(0.001)
end

EDIT: Made a script typo.

Are there any errors? Anything in the output? or the part just does not move?

In the output it says:

Y cannot be assigned to

You can change the CFrame then, change the CFrame of the part, ill send an example

You need to edit the Position as a Vector3, you cannot directly modify the different axes of it. Instead of

Position.Y = 5

You need to do:

Position = Vector3.new(Position.X, 5, Position.Z)

tl;dr: axes of a vector3 are read-only

Obviously, the “Position.X” and “Position.Z” are globals. What would I set them to to not affect the X, Y, and Z?

You can do this:

local lift = script.Parent.Height
while true do
	script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,lift.Value,0)
	wait(0.001)
end

Is the part anchored? because if it is not, then it might be moving a little laggy

That just makes it constantly rise. How do I make it fire when lift.Value changes? If I remove the while true do, it won’t change it at all because the script will only run once.

Only once?Do you mean one smooth movement? If that’s the case, you can lerp the part

What I’m trying to make happen is when lift.Value changes, it will update accordingly. It doesn’t matter if the movement is smooth.

Oh, okay, now I understand, let me send it.

You can use a for loop instead of a while loop if you don’t want it to run forever.

local Amountoftimes = 50
for I =1, Amountoftimes do
--This will run 50 times
wait(0.001)
end
local lift = script.Parent.Height

lift:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,lift.Value, 0)
end)

Every time the value will change, it will change the part’s height
You can do this.

You can change your script to this:

script.Parent.Position = script.Parent.Position + Vector3.new(0, lift.Value, 0)

or you can utilize TweenService:

local TS = game:GetService("TweenService")
local RS = game:GetService("Runservice")
local TI = TweenInfo.new(1)

while true do
    local Anim = TS:Create(script.Parent, TI {Position = script.Parent.Position + Vector3.new(0, lift.Value * 60, 0)})  
    --[[ note on why I multiplied by 60. RS.HeartBeat runs 60 times per second, 
         which is the fastest roblox can process code 
    --]]
    Anim:Play()
    Anim.Completed:Wait()
end

This method is capable of having a smooth animation.

I accidentally replied to myself, but this is the solution, it works for me

local lift = script.Parent.Height

lift:GetPropertyChangedSignal(“Value”):Connect(function()
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0,lift.Value, 0)
end)


Every time the value will change, it will change the part’s height
You can do this.