So first step in coding an elevator is the doors automatically moving. One of my door(door1) moves, but the other one doesn't budge(door2). Please help?
01 | debounce = true |
02 | script.Parent.Touched:connect( function (hit) |
03 | if hit.Parent:FindFirstChild( "Humanoid" ) and debounce then |
04 | debounce = false |
05 | for moved 1 = 933.301 , 939.111 , 0.5 do |
06 | game.Workspace.Door 1. CFrame = CFrame.new(Vector 3. new(moved 1 , 4.642 , - 386.874 )) |
07 | wait( 0.1 ) |
08 | end |
09 | for moved 2 = 926.038 , 920.378 , 0.5 do |
10 | game.Workspace.Door 2. CFrame = CFrame.new(Vector 3. new(moved 2 , 4.642 , - 386.874 )) |
11 | end |
12 | end |
13 | end ) |
some lines of the script were too long to fit in the code block so that's why some lines of code run on into the next line.
1 | for moved 2 = 926.038 , 920.378 , 0.5 do |
Your start number is greater than your end number, but you have a positive increment. So basically you're trying to go from 926 to 920 by adding 0.5 each time. Just make the increment negative.
1 | for moved 2 = 926.038 , 920.378 , - 0.5 do |
This should work.
But seriously, dude... your code is a mess lol. Just add to the CFrame, don't use exact coordinates. This will also let you move the doors wherever you want and they should still work.
1 | local door 1 = workspace.Door 1 |
2 |
3 | for i = 1 , 5 do |
4 | door 1. CFrame = door 1. CFrame * CFrame.new( 0.5 , 0 , 0 ) |
5 | end |
Also remember that you never set your debounce back to true
.