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

How do I anchor one side in rotation? (edited)

Asked by 8 years ago

script:

local door = script.Parent

--position before moving = 61.595, 3.5, -123.086
--position after moving = 65.779, 3.5, -121.335
--rotation before moving = 0, 0, 0
--rotation after moving = 180, 50, 180
--have no clue what im doing rn v

function doormove(onClick)
    for x = 61.595, 65.779, .4 do
    for z = -123.086, -121.335, .2 do
    workspace.Model:SetPrimaryPartCFrame(CFrame.new(x, 0, z))
    for h = 0, 180, 20 do
    for e = 0, 50, 5 do
    for y = 0, 180, 20 do
    workspace.Model:SetPrimaryPartCFrame(CFrame.Angles(h, e, y))
    end
    end
    end
    end
    end
end

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

when i click it lags the server and it disappears

i want it to swing open like a normal door but when i click it just disappears. i used to have just one brick and the center would swing, but the primary part of the model is on the side of the door as the center for the moving.

1 answer

Log in to vote
0
Answered by 8 years ago

The problem probably lies in this part of your code:

workspace.Model:SetPrimaryPartCFrame(CFrame.new(x, 0, z))

What you're doing is setting the Y position to 0, so depending on the height of the door and ground, it might be below the ground.

To fix this, I suggest changing it to this:

workspace.Model:SetPrimaryPartCFrame(CFrame.new(x, 3.5, z))

I'm assuming the comments are giving the correct Y position. Also, I would suggest adding a wait() after the rotational for loops, so you can actually see the door open:

local door = script.Parent

--position before moving = 61.595, 3.5, -123.086
--position after moving = 65.779, 3.5, -121.335
--rotation before moving = 0, 0, 0
--rotation after moving = 180, 50, 180
--have no clue what im doing rn v

function doormove(onClick)
    for x = 61.595, 65.779, .4 do
        for z = -123.086, -121.335, .2 do
            door:SetPrimaryPartCFrame(CFrame.new(x, 3.5, z))
            for h = 0, 180, 20 do
                for e = 0, 50, 5 do
                    for y = 0, 180, 20 do
                        door:SetPrimaryPartCFrame(CFrame.Angles(h, e, y))
                    end
            end
            end
            wait(0.1) -- Change to adjust speed.
    end
    end
end

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

Finally, I noticed that you put the ClickDetector in a Model. I don't think this works; you should put it in a part and update the last line accordingly. I also noticed you used workspace.Model. This will make the script break if you change the door's parent or rename it. I fixed that in the code above.

The indentation didn't come out very well, I noticed. But you should always indent your code; it increases readability and makes it easier to spot errors related to end statements.

Ad

Answer this question