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
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.
As other people have pointed out, you also apparently can't set on a single axis.
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
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.
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