local Brick = script.Parent
function MoverTest()
game.Workspace.Brick.Position = Vector3.new(-100.5, 80, 231)
wait(0.5)
game.Workspace.Brick.Position = Vector3.new(-100.5, 90, 231)
wait(0.5)
game.Workspace.Brick.Position = Vector3.new(-100.5, 100, 231)
wait(0.5)
end
MoverTest() repeat
until MoverTest() ~= nil
So I got this code done!(proud of myself) but is there an easier way to move the brick?
1 answer
Wow you're getting a lot better! :D
I'm assuming you're trying to move the brick up 10 studs every time the loop runs. You're really close but you need to create a variable and put the variable into the Y position.
Also, script.Parent is referencing the Brick, you can just use the variable "Brick" instead of going through game.Workspace.Brick every single time.
local Brick = script.Parent
local yPos = 80
local function MoverTest()
Brick.Position = Vector3.new(-100.5, yPos, 231)
yPos = yPos + 10
wait(0.5)
end
repeat
MoverTest()
until yPos == 70
We're creating a variable called 'yPos' that we are going to add 10 to every time it repeats. In the function MoverTest(), we are setting the brick's position to yPos, which is 80, then adding 10 to yPos.
This means next time we use yPos it will be 90, then 100, then 110... and it will run forever... until yPos == 70. Of course we know yPos is never going to equal 70, so it's going to do this forever... until you stop the game :P
(also the wait is there so the game doesn't crash by looping a bunch of times)
5 comments
oh okay! Also is it necessary for me to use "local Brick".... could I not jut use "Brick"??
Yes you can just use 'Brick', but you should put local in front, it's a better habit for the future.
Global variables are bad practice. They clutter the global environment, and if used improperly they can make your code messy.
global variables? Is global when u use local?
Global variables just clutter code and underline it in blue, but in some really glitchy haxxy codes, you just may need them..
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
You need to put the MoverTest() after the repeat.
Or you could use BodyPosition to move the part more smootly.https://wiki.roblox.com/index.php?title=API:Class/BodyPosition
lerp
GGButNO_RE it won't work?