aura = Instance.new("Part", game.Workspace)
for i=5, 10 do
wait(0.5)
aura.CFrame = aura.CFrame + CFrame.new(i,i,i)
end
How do i make a part move at a specific position upward at a constant rate?
4 answers
You can't add CFrames together or set the value like that. You can do
aura = Instance.new("Part", game.Workspace)
for i=1, 10 do
wait(0.5)
aura.CFrame = aura.CFrame + Vector3.new(0,5,0)-- Edit the middle value to how much you want it to move up.
end
##Your Problem
On
line 5you are adding i onto every axis. In order to move "up" - you must add to the Y-axis.Also, CFrames should be multiplied. Not added.
"constant rate" --> To make the part move at a constant rate, you have to replace "i" with a number, since "i" changes with each iteration. Using "i" is more like a compound rate.
##Code
local aura = Instance.new("Part", workspace)
local rate = 1;
for i = 5, 10 do
wait(0.5)
aura.CFrame = aura.CFrame * CFrame.new(0,rate,0)
end
I suggest making this a while loop, or editing the for loop's bounds, seeing as it will currently only iterate 5 times.
First, you have to understand: What are the coordinates I am using?
There are X, Y, and Z coordinates that determine the position of an instance on a grid. The Z coordinate will not be important right now in your situation.
The X coordinate determines where the instance is horizontally.
The Y coordinate determines where the instance is vertically.
Using this, we can now fix up a script to match your situation.
aura = Instance.new("Part", game.Workspace)
for i = 5, 10 do
wait(0.5)
aura.CFrame = aura.CFrame + Vector3.new(0, 1, 0)
end
This raises the CFrame of the part by one Y coordinate every 0.5 seconds. It will always raise by one, being a constant rate.
Hope this helped! Please accept this answer!
The previous answers posted are all correct! I just want to give a little bonus answer towards how to move a model, no matter what rotation it is at. The model must have a PrimaryPart.
local model = game.Workspace.Model
local prime = model.PrimaryPart
local function moveModel()
for i = 1, 200 do
model:SetPrimaryPartCFrame(prime.CFrame * CFrame.new(0, 1, 0))
wait()
end
end
moveModel()
Basically, the SetPrimaryPartCFrame takes the Primary Part of the model and CFrames it at a constant rate of 1 stud per wait(). This can be applied to other parts too, as mentioned from previous answers. :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
