Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Am I doing something wrong? My onclick door won't stay in place?

Asked by 10 years ago

Every time I try to test out the door that opens when clicked, it moves up on the top of the building. All parts are anchored, and I have no idea what I'm doing wrong.

local open = false;

script.Name = "Clickable Door Script"; -- On the assumption that this is that script

script.Parent.ClickDetector.MouseClick:connect(function()

    if not open then -- Checks if closed

        script.Parent.Rotation = Vector3.new(0, 110, 0);

        open = true;

    else -- If open

        script.Parent.Rotation = Vector3.new(0, 0, 0);

        open = false;

    end

end)

2 answers

Log in to vote
0
Answered by 10 years ago

Mind if you give us the script?

0
I edited the question and put the script in AudreyJeanx 55 — 10y
Ad
Log in to vote
0
Answered by
Maxomega3 106
10 years ago

The problem is that you're using Vector3 values rather than CFrame values. The main difference between CFrame and Vector3 is that CFrames are more (let's say) "aggressive" on their place. They can be used to move a brick inside another brick without a problem. If a Vector3 finds that its position in the Workspace has already been taken, it will jump to the same point, but as low as it can without disturbing other bricks in its space.

Here's a revised code:

local open = false; -- so glad you declare variables efficiently

script.Name = "Clickable Door Script"; -- On the assumption that this is that script

script.Parent.ClickDetector.MouseClick:connect(function()

    if not open then -- Checks if closed

        script.Parent.Rotation = CFrame.Angles (0, 110, 0);

        open = true;

    else -- If open

        script.Parent.Rotation = CFrame.Angles (0, 0, 0);

        open = false;

    end

end)


0
Thank you! :) AudreyJeanx 55 — 10y

Answer this question