Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

0

Do not only post code, or only post an explanation. Both are required to make a good question.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.