Trying to make a basic code door.. it works but the blocks wig out when I try to shrink them. I basically want them to "slide up", and to create this effect while not making surrounding scenery look weird, I need to shrink them from the bottom up. My following code does not work and I have no idea why, any insight?
local function OpenDoor() LeftDoor.CanCollide = false; RightDoor.CanCollide = false; for Key = 0, 1, 0.01 do LeftDoor.Size = (LeftDoor.Size - Vector3.new(0, Key, 0)); RightDoor.Size = LeftDoor.Size LeftDoor.CFrame = (LeftDoor.CFrame * CFrame.new(0, (Key / 2), 0)); RightDoor.CFrame = (RightDoor.CFrame * CFrame.new(0, (Key / 2), 0)); wait(1 / 15); end; end; local function CloseDoor() for Key = 0, 1, 0.01 do LeftDoor.Size = (LeftDoor.Size + Vector3.new(0, Key, 0)); RightDoor.Size = LeftDoor.Size LeftDoor.CFrame = (LeftDoor.CFrame * CFrame.new(0, -(Key / 2), 0)); RightDoor.CFrame = (RightDoor.CFrame * CFrame.new(0, -(Key / 2), 0)); wait(1 / 15); end; LeftDoor.CanCollide = true; RightDoor.CanCollide = true; end;
I had to google what wig out meant. Is it a British saying?
The problem you might be running into here is that we are using the new size and new positions of the doors. Meaning that when we decrease the size by some amount, Key, we are doing that each time the loop runs. There are two ways to fix this. We can preserve what the old variables were, OR change how the positions and sizes are incrementally changed.
Example one.
for Key = 0, 1, 0.01 do LeftDoor.Size = (LeftDoor.Size - Vector3.new(0, 0.01, 0)); LeftDoor.CFrame = (LeftDoor.CFrame * CFrame.new(0, 0.01 / 2, 0)); -- ... and so on. end
Example two.
local originalsize = LeftDoor.Size local originalposition = LeftDoor.CFrame for Key = 0, 1, 0.01 do LeftDoor.Size = (originalsize - Vector3.new(0, Key, 0)); LeftDoor.CFrame = (originalposition * CFrame.new(0, Key / 2, 0)); -- and so on. end
I think both of those strategies will work.