Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I check the Y Position of a part and change it if it's less than a certain value?

Asked by 8 years ago

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!

0
I can't help. I do not know how to do stuff like that. Try a bodyposition thing and make a script to change it. Using if things are helpful. Just remember that. If you want me to make you a brick as a template then just message me on ROBLOX. chexburger 358 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
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.

0
I'll definitely look into it. Thank you! Brinceous 85 — 8y
Ad

Answer this question