Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make a door that goes up?

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

6 comments

0

You can't set the individual axes, and due to floating point imprecision your while loop might be an infinite loop.

0

he say do >= not ~=

0

Or <

0

also u didnt show the script for the button so we dont even know if that would work.

3

dont sass me incapaz he knows what i mean

0

yeah INCAPAble!!

2 answers

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.

4 comments

0

lerp sounds like the noise a dog makes drinking water

0

lerp is linear interpolation. And Position is "stupid" becausen Position is a Vector3 value and Vector3 has collision detection

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.

0

When you set the .Position property of an instance roblox does collision checks.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.