So I made this script to where a door can slide up slowly but not too slow and when it keeps sliding up, it gets faster and faster. But I am not wanting it to go faster and faster, I want it to stay at a constant speed.
local Door = game.Workspace.Door for i = 0,.2,.001 do Door.CFrame = Door.CFrame + Vector3.new(0,i,0) wait() print(i) end
What is wrong?
The door is rising faster because i
is stacking up every time.
If the starting position was 0, 0, 0
:
loop #1: It adds 0 .001 studs
loop #2: It adds 0.002 studs, making it's position
0, 0.003, 0
loop #3: It adds 0.003 studs, making it's position
0, 0.006, 0
See where I am going? Instead of rising just 0.001 every time, it is rises the amount of i
for every loop, meaning it will rise more every time - making it in turn, appear faster.
How do you fix it?
Simple, you just add a set amount every time:
local Door = game.Workspace.Door local Step = 0.001 -- how much it rises, so you don't have to define it twice for i = 0,0.2,Step do Door.CFrame = Door.CFrame + Vector3.new(0,Step,0) wait() end
Hope I helped!
~TDP
You can use BodyVelocity.