Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I make a door that goes up?

Asked by 6 years ago

I'm looking to make a bunker door that goes up, then down. Yes I have made the measurements, but when I tested it, it didn't even move when I clicked the button? Here's a sample:

1while game.Workspace.NAAFBunker.Door.Position.y ~= 20.1 do
2    game.Workspace.NAAFBunker.Door.Position.y = game.Workspace.NAAFBunker.Door.Position.y + 0.1
3    wait(0.1)
4end
5wait(5)
6while game.Workspace.NAAFBunker.Door.Position.y ~= 11.1 do
7    game.Workspace.NAAFBunker.Door.Position.y = game.Workspace.NAAFBunker.Door.Position.y - 0.1
8    wait(0.1)
9end
0
You can't set the individual axes, and due to floating point imprecision your while loop might be an infinite loop. User#24403 69 — 6y
0
he say do >= not ~= DinozCreates 1070 — 6y
0
Or < User#24403 69 — 6y
0
also u didnt show the script for the button so we dont even know if that would work. DinozCreates 1070 — 6y
View all comments (2 more)
3
dont sass me incapaz he knows what i mean DinozCreates 1070 — 6y
0
yeah INCAPAble!! Gey4Jesus69 2705 — 6y

2 answers

Log in to vote
3
Answered by
fredfishy 833 Moderation Voter
6 years ago
Edited 6 years ago

You need to use CFrame, not Position, when moving the door.

ROBLOX is stupid, and if you use Position, it won't allow intersections between two difference parts.

Edit

As other people have pointed out, you also apparently can't set on a single axis.

End edit

01door = Workspace.NAAFBunker.Door
02 
03-- Don't use ~= and == when working with decimals
04while door.Position.y < 20.1 do
05    door.CFrame = door.CFrame * CFrame.new(0, 0.1, 0)
06    wait(0.1)
07end
08 
09wait(5)
10 
11while door.Position.y > 11.0 do
12    door.CFrame = door.CFrame * CFrame.new(0, 0.1, 0)
13    wait(0.1)
14end

However, you can also use the strangely named "lerp" method for slightly nicer, more efficient code.

01door = Workspace.NAAFBunker.Door
02height = door.Size.y
03closedCFrame = door.CFrame
04openCFrame = closedCFrame * CFrame.new(0, height, 0)
05 
06for i = 0, 1, 0.05 do
07    door.CFrame = closedCFrame:lerp(openCFrame, i)
08    wait(0.1)
09end
10 
11wait(5)
12 
13for i = 0, 1, 0.05 do
14    door.CFrame = openCFrame:lerp(closedCFrame, i)
15    wait(0.1)
16end

or something along those lines

NB

The reason we don't use == and ~= when working with decimals is because computers don't actually store them properly. What looks like a 2.1 is probably actually a 2.1000000003 or something.

The operators == and ~= check for exact equality, so if we're checking for 2.1 and the real value is 2.100000003, they won't work as we expect.

0
lerp sounds like the noise a dog makes drinking water DinozCreates 1070 — 6y
0
lerp is linear interpolation. And Position is "stupid" becausen Position is a Vector3 value and Vector3 has collision detection User#24403 69 — 6y
0
It's position which has the collision detection, not Vector3. Vector3 is just a 3 dimensional vector class. If Vector3 somehow had collison detection you wouldn't even be able to define duplicate Vector3 values. fredfishy 833 — 6y
0
When you set the `.Position` property of an instance roblox does collision checks. EpicMetatableMoment 1444 — 6y
Ad
Log in to vote
1
Answered by 6 years ago

When attempting to move a part, you must use Vector3 or CFrame. You cannot operate on a position regularly

01x = game.Workspace.NAAFBunker.Door.Position.X
02y = game.Workspace.NAAFBunker.Door.Position.Y
03z = game.Workspace.NAAFBunker.Door.Position.Z
04 
05while y <= 20.1 do
06game.Workspace.NAAFBunker.Door.Position = Vector3.new(x,y+0.1,z)
07wait(0.1)
08end
09 
10wait(5)
11 
12while y >= 11.1 do
13game.Workspace.NAAFBunker.Door.Position = Vector3.new(x,y-0.1,z)
14    wait(0.1)
15end

Answer this question