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

Why is my part not going up? Do I need to use CFrame?

Asked by 7 years ago

Here is my script:

while true do
    wait(math.random(2.5, 8.5))
    while not script.Parent.Position.Y == 53.5 do
        script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y  + 0.5, script.Parent.Position.Z)
    end
    wait(math.random(2.5, 8.5))
    while not script.Parent.Position.Y == 28.5 do
        script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y  - 0.5, script.Parent.Position.Z)
    end
end

Please fix it.

0
Do not only post code, or only post an explanation. Both are required to make a good question. hiimgoodpack 2009 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

What your problem is that you have multiple while loops. A while loop goes on infinitely unless you use break to stop the loop.The solution to this problem is to include if statements instead of while loops.

math.randomseed(tick()) -- Truly makes randomizers truly random
while wait() do -- waits 1/30th of a second then,does the rest
    wait(math.random(2.5, 8.5))
    if not script.Parent.Position.Y == 53.5 do
        script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y  + 0.5, script.Parent.Position.Z)
    end
    wait(math.random(2.5, 8.5))
    if not script.Parent.Position.Y == 28.5 do
        script.Parent.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y  - 0.5, 
script.Parent.Position.Z)
    end
end
Ad

Answer this question