I want to make a door that goes up in the "Y" axis, I think it's the Y axis. (Make it going up) I want it to go 1 stud up every 1 second.
Door = script.Parent wait(9) Door.Position = Vector3.new(-57.48, 7.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 8.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 9.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 10.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 11.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 12.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 13.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 14.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 15.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 16.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 17.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 18.2, 7) wait(1) Door.Position = Vector3.new(-57.48, 19.2, 7) wait(1)
Well a more efficient way to do this would be to use a for loop. To do this, we'll need to set up the loop like so:
for i = 1,12 do --Code end
So now, i is the variable that stores the current iteration we're on. This'll make the 'code' part happen 12 times in a row.
To apply this to your code, we'll use this to our advantage, and just add 1 to the y value per loop:
Door = script.Parent wait(9) for i = 1,12 do Door.CFrame = CFrame.new(Door.Position) * CFrame.new(0,1,0) --Adds 1 to position every loop wait(1) end
So now your code should work. If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P
Ok, a much more efficient way to do what you're describing is using a for
loop and defining the position of the door and adding 1 to the y axis of the door.
Example:
local Door = script.Parent -- Don't forget your locals wait(9) for i =1,12 do -- This loop will start at 1 and keep running until it has ran 10 times. With i as the number of iterations Door.Position = Door.Position - Vector3.new(0,1,0) -- This is much more efficient then listing each vector3 position for the door wait(1) -- Will wait one second end
1 local Door = script.Parent -- Don't forget your locals 2
3 wait(9) 4 for i =1,12 do -- This loop will start at 1 and keep running until it has ran 10 times. With i as the number of iterations 5 Door.Position = Door.Position - Vector3.new(0,1,0) -- This is much more efficient then listing each vector3 position for the door 6 wait(1) -- Will wait one second 7 end