I'm trying to make a part that rotates and kind of 'bobs' up and down. While it's rotating fine - the Y rotation value of the block is changing -, it doesn't move at all along the Y Axis.
local block = script.Parent local yRotVal = 0 local yPos = block.Position.Y local yPosTop = yPos + 5 local yPosBottom = yPos - 5 while true do wait() block.Rotation = Vector3.new(0,yRotVal,0) yRotVal = yRotVal + .5 while yPos < yPosTop do --This is where the issue is wait() --< yPos = yPos + .5 --< print (yPos) --< end end
Where it's asked to print the value of the yPos, it does this properly. The number increases by .5 each time, but the position stays the same. The output looks as follows:
1,
1.5,
2,
2.5,
3,
3.5,
4,
4.5,
5,
5.5
, so I know it's reaching that part of the code, I'm just not sure why the Y position isn't changing. Thanks for any help!
local block = script.Parent local yRotVal = 0 local yPos = block.Position.Y local yPosTop = yPos + 5 local yPosBottom = yPos - 5 while true do wait() block.Rotation = Vector3.new(0,yRotVal,0) yRotVal = yRotVal + .5 if block.Position.Y < yPosTop then block.Position = Vector3.new(block.Position.X,yPosTop,block.Position.Z) end end
This way of coding isn't recommended in my opinion. You should probably be using BodyPosition instead.