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

So I got this code done!(proud of myself) but is there an easier way to move the brick?

Asked by 5 years ago
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


0
You need to put the MoverTest() after the repeat. Pojoto 329 — 5y
0
Or you could use BodyPosition to move the part more smootly.https://wiki.roblox.com/index.php?title=API:Class/BodyPosition GGButNO_RE 61 — 5y
0
lerp greatneil80 2647 — 5y
0
GGButNO_RE it won't work? hawkeye1940 8 — 5y

1 answer

Log in to vote
0
Answered by
Pojoto 329 Moderation Voter
5 years ago

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)

0
oh okay! Also is it necessary for me to use "local Brick".... could I not jut use "Brick"?? hawkeye1940 8 — 5y
0
Yes you can just use 'Brick', but you should put local in front, it's a better habit for the future. Pojoto 329 — 5y
0
Global variables are bad practice. They clutter the global environment, and if used improperly they can make your code messy. User#19524 175 — 5y
0
global variables? Is global when u use local? hawkeye1940 8 — 5y
0
Global variables just clutter code and underline it in blue, but in some really glitchy haxxy codes, you just may need them.. greatneil80 2647 — 5y
Ad

Answer this question