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

Moving a block up and down?

Asked by 9 years ago

Ive been looking around the website & Roblox wiki but i cant find anything to my knowledge about moving a block up and down about 1 / 1 & a half studs

If anyone knows somewhere where this is explained can you link it, thanks!

2 answers

Log in to vote
3
Answered by 9 years ago

For future reference: Please provide the sufficient material, code snippets you may have tried, any specific idea on what it should do, etc.

To accomplish this task, you must change the Position of the part using a Vector3.new().

To use it in a loop, it would look like this:

--this script would be inside the part
local brick=script.Parent --creating a new variable named brick, referencing our part. "script" is a built-in object that references the actual script.
while wait(1) do --wait a second before running the code again
for I=1,10 do --begin a "for" loop, we are going to move the part up very little by little to make it seem like it is sliding.
brick.Position=brick.Position+Vector3.new(0,0.1,0) --add 0.1 on the Y scale (Vertical) to increase the brick's position
wait() --wait a fraction of a millisecond, or else it doesn't appear as a sliding brick.
end --end the "for" loop
wait(1) --pause a second
for I=1,10 do --This section is pretty much just a repeat.
brick.Position=brick.Position+Vector3.new(0,-0.1,0) --subtract 0.1 on the Y scale (Vertical) to decrease the brick's position
wait()
end
end --end the loop

The issue with this code is, if something is in the way, the part will jump immediately to the lowest point available which would be the top of the brick that is in the way. Our solution is CFrame.new(). "CFrame" is just a shortened version of CoordinateFrame.

This would be the version with CFrame:

--this script would be inside the part
local brick=script.Parent --creating a new variable named brick, referencing our part. "script" is a built-in object that references the actual script.
while wait(1) do --wait a second before running the code again
for I=1,10 do --begin a "for" loop, we are going to move the part up very little by little to make it seem like it is sliding.
brick.CFrame=brick.CFrame+Vector3.new(0,0.1,0) --increase the height, this time with the CFrame. Notice we are still using a Vector3 property to add on, but what counts is the CFrame that we're adding on to.
wait() --wait a fraction of a millisecond, or else it doesn't appear as a sliding brick.
end --end the "for" loop
wait(1) --pause a second
for I=1,10 do --This section is pretty much just a repeat.
brick.CFrame=brick.CFrame+Vector3.new(0,-0.1,0) --subtract 0.1 on the Y scale (Vertical) to decrease the brick's position
wait()
end
end --end the loop

You can read more about CFrame here. I hope this helped!

1
Thanks for the help & explanation, will remember the code snippets/sources thing for the future Rythian2277 65 — 9y
Ad
Log in to vote
0
Answered by
dirk29 0
9 years ago

The easiest way would be,

local brick = script.Parent
for i = 1,15 do
brick.CFrame  = brick.CFrame*CFrame.new(0,-.1,0)
wait(.1)
end

Answer this question