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

Sliding Door won't work. CFrame (Position + Vector3) not moving?

Asked by 7 years ago

I have a grouped everything together. I also referenced this video: https://www.youtube.com/watch?v=ZnBz_kbSnm8&index=45&list=WL&t=1115s

-Automatic Door, Script, -Door1, Frame, Frame, Frame, Frame, Glass, -Door2, Frame, Frame, Frame, Frame, Glass, Frame (x11), Glass (x3), Sensor,

Script:

door1 = script.Parent.Door1
door2 = script.Parent.Door2

doorClosed = true

script.Parent.Sensor.Touched:connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h then
        if doorClosed then
            doorClosed = false
            for i = 1,30.3 do
                door1.CFrame = CFrame.new(door1.Position + Vector3.new(0,0,0.3))
                door2.CFrame = CFrame.new(door2.Position + Vector3.new(0,0,-0.3))
                wait()
            end
            wait(0.3)
            for i = 1,30.3 do
                door1.CFrame = CFrame.new(door1.Position + Vector3.new(0,0,-0.3))
                door2.CFrame = CFrame.new(door2.Position + Vector3.new(0,0,0.3))
                wait()
            end
            doorClosed = true
        end
    end
end)

Please help me, thank you.

1
Is there any output? Have you added print()s to make sure the loops are starting at all? BlueTaslem 18071 — 7y
0
I have no clue what an output is. And I did not add print(). PvPNinjaDragon 35 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

First off, output is the information that the program processes and sends out. Print() is the easiest and simplest output function.

The easiest way to make a sliding door is not with CFrame, but with a PrismaticConstraint. Simply attach one attachment to the door, and one to the wall it is sliding from, and put a PrismaticConstraint in between. Then, change the ActuatorType to Servo, mess around with the settings a bit until you get what you like, change the TargetPosition to 0, and put the following code in your script:

door1 = script.Parent.Door1
prismatic1 = door1.PrismaticConstraint
door2 = script.Parent.Door2
prismatic2 = door2.PrismaticConstraint
--Assuming that you already have the PrismaticConstraints installed correctly, that is...

doorClosed = true

script.Parent.Sensor.Touched:connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h and doorClosed then
            doorClosed = false
        prismatic1.TargetPosition = 45 --or whatever you want
        prismatic2.TargetPosition = 45
        wait() --however long it takes for your doors to open
        prismatic1.TargetPosition = 0
        prismatic2.TargetPosition = 0
        wait() --the same amount of time
        doorClosed = true
    end
end)

See how much cleaner that looks using a Constraint instead of a CFrame?

Ad

Answer this question