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

Problem with my on-click door?

Asked by 10 years ago

My on-click door script won't stay in place. Every time I click on it, it goes on the top of the building. Here's the script I used:

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)


I was then told to use the script below, but every time I run it, the output box says, "12:56:47.119 - Workspace.Door.Clickable Door Script:9: bad argument #3 to 'Rotation' (Vector3 expected, got userdata)"

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)



1 answer

Log in to vote
2
Answered by 10 years ago

I kind of agree with the 2. script, but it's still very wrong. Anyway, you shouldn't set rotation, use it as a read only property.

local open = false;
local originalCF = script.Parent.CFrame

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.CFrame  = originalCF * CFrame.Angles(0, math.rad(110), 0) * CFrame.new(script.Parent.Size.x/4, 0, script.Parent.Size.x/2)

        open = true;

    else -- If open

        script.Parent.CFrame = originalCF;

        open = false;

    end

end)
0
It's still like messed up. Can I party you and have you come to my place so you can help me? AudreyJeanx 55 — 10y
0
Did you edit it yet? AudreyJeanx 55 — 10y
0
I guess this should do. ZarsBranchkin 885 — 10y
0
Thanks! It worked :) AudreyJeanx 55 — 10y
Ad

Answer this question