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

How would I make the door stop moving?

Asked by 4 years ago

So, I created this script that's supposed to open the door using a keycard and a keycard slider.

local open = false

script.Parent.Touched:Connect(function(hit)
    if hit:IsA("Part") then
        if hit.Name == "Handle" then
            if hit.Parent.Name == "Keycard" then
                local door = script.Parent.Parent.Parent.Parent.CDDoor.Door
                if open == false then
                    open = true
                    repeat wait()
                    door:SetPrimaryPartCFrame(door:GetPrimaryPartCFrame() * CFrame.new(0,0,0 + -0.1))
                    until door.MovingPart.CFrame == Vector3.new(-21.429,7.775,6)
                end
            end
        end
    end
end)

The door just keeps on going, and won't stop at the designated point.

https://gyazo.com/130473033224178d1d98b845f14b9330

1 answer

Log in to vote
0
Answered by 4 years ago
local open = false

script.Parent.Touched:Connect(function(hit)
    if hit:IsA("Part") then
        if hit.Name == "Handle" then
            if hit.Parent.Name == "Keycard" then
                local door = script.Parent.Parent.Parent.Parent.CDDoor.Door
                if open == false then
                    open = true
                    repeat wait()
for i = 1,60 do
wait(.1)
door.CFrame = door.CFrame * CFrame.new(0,0,0.1)
                end
            end
        end
    end
end)
end)

Ad

Answer this question