Ad
Log in to vote
0

Shrinking the block not working?

Asked by 2 months ago

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;
0
Your gonna bother to put semicolons to end lines on every line besides line 16 and line 6? hiimgoodpack 1487 — 2mo
0
Wow, thanks for completely missing my point. It was a mistake because I was c+p'ing. Great help, jackass. MedievalBeast4 4 — 2mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by
kools 259
1 month ago

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.

0
To your question - No, I'm just a weird ol' regular american lol. And thank you! MedievalBeast4 4 — 1mo
Ad

Answer this question



Ad