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!
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!
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