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 5 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:

while game.Workspace.NAAFBunker.Door.Position.y ~= 20.1 do
    game.Workspace.NAAFBunker.Door.Position.y = game.Workspace.NAAFBunker.Door.Position.y + 0.1
    wait(0.1)
end
wait(5)
while game.Workspace.NAAFBunker.Door.Position.y ~= 11.1 do
    game.Workspace.NAAFBunker.Door.Position.y = game.Workspace.NAAFBunker.Door.Position.y - 0.1
    wait(0.1)
end
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 — 5y
0
he say do >= not ~= DinozCreates 1070 — 5y
0
Or < User#24403 69 — 5y
0
also u didnt show the script for the button so we dont even know if that would work. DinozCreates 1070 — 5y
View all comments (2 more)
3
dont sass me incapaz he knows what i mean DinozCreates 1070 — 5y
0
yeah INCAPAble!! Gey4Jesus69 2705 — 5y

2 answers

Log in to vote
3
Answered by
fredfishy 833 Moderation Voter
5 years ago
Edited 5 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

door = Workspace.NAAFBunker.Door

-- Don't use ~= and == when working with decimals
while door.Position.y < 20.1 do
    door.CFrame = door.CFrame * CFrame.new(0, 0.1, 0)
    wait(0.1)
end

wait(5)

while door.Position.y > 11.0 do
    door.CFrame = door.CFrame * CFrame.new(0, 0.1, 0)
    wait(0.1)
end

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


door = Workspace.NAAFBunker.Door height = door.Size.y closedCFrame = door.CFrame openCFrame = closedCFrame * CFrame.new(0, height, 0) for i = 0, 1, 0.05 do door.CFrame = closedCFrame:lerp(openCFrame, i) wait(0.1) end wait(5) for i = 0, 1, 0.05 do door.CFrame = openCFrame:lerp(closedCFrame, i) wait(0.1) end

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 — 5y
0
lerp is linear interpolation. And Position is "stupid" becausen Position is a Vector3 value and Vector3 has collision detection User#24403 69 — 5y
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 — 5y
0
When you set the `.Position` property of an instance roblox does collision checks. EpicMetatableMoment 1444 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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

x = game.Workspace.NAAFBunker.Door.Position.X
y = game.Workspace.NAAFBunker.Door.Position.Y
z = game.Workspace.NAAFBunker.Door.Position.Z

while y <= 20.1 do
game.Workspace.NAAFBunker.Door.Position = Vector3.new(x,y+0.1,z)
wait(0.1)
end

wait(5)

while y >= 11.1 do
game.Workspace.NAAFBunker.Door.Position = Vector3.new(x,y-0.1,z)
    wait(0.1)
end

Answer this question