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

How do I make a Keycard Door that rotates?

Asked by 5 years ago

I'm trying to make a game with keycard doors that rotate when you put the correct keycard into them. I've only been able to make a Door that goes to the side so far and nothing I've tried has made it work. I'm trying to edit function openDoor() and function closeDoor() to make the door actually rotate 90 Degrees instead of just making the door go to the side.

This is my current code:

local door = script.Parent
local bool = false
local CanOpen1 = true
local CanClose1 = false
local AccessDenied = script.Parent.AccessDenied
local AccessGranted = script.Parent.AccessGranted
local clearance = {
    ["Wrong Keycard"] = true,
    ["Correct Keycard"] = true
}

function openDoor()
    script.Parent.DoorOpen:play()
    for i = 3,(door.Size.z / 0.1) do
        wait()
        door.CFrame = door.CFrame - (door.CFrame.lookVector * 0.2)
    end
end

function closeDoor()
    script.Parent.DoorClose:play()
    for i = 3,(door.Size.z / 0.1) do
        wait()
        door.CFrame = door.CFrame + (door.CFrame.lookVector * 0.2)
    end
end

script.Parent.Parent.KeycardReader1.touched:connect(function(touch)
    if touch.Name == "Handle" and clearance[touch.Parent.Name] and CanOpen1 == true then

        CanOpen1 = false
        AccessGranted:Play()
        openDoor()
        wait(1)
        CanClose1 = true
    elseif touch.Name == "Handle" and clearance[touch.Parent.Name] and CanClose1 == true then
        CanClose1 = false
        AccessGranted:Play()
        closeDoor()
        wait(1)
        CanOpen1 = true
    elseif touch.Name == "Handle" and not clearance[touch.Parent.Name] and not bool then
        bool = true
        AccessDenied:Play()
        wait(2)
        bool = false
    end
end)

script.Parent.Parent.KeycardReader2.touched:connect(function(touch)
    if touch.Name == "Handle" and clearance[touch.Parent.Name] and CanOpen1 == true then
        CanOpen1 = false
        AccessGranted:Play()
        openDoor()
        wait(1)
        CanClose1 = true
    elseif touch.Name == "Handle" and clearance[touch.Parent.Name] and CanClose1 == true then
        CanClose1 = false
        AccessGranted:Play()
        closeDoor()
        wait(1)
        CanOpen1 = true
    elseif touch.Name == "Handle" and not clearance[touch.Parent.Name] and not bool then
        bool = true
        AccessDenied:Play()
        wait(2)
        bool = false
    end
end)
0
You want a dynamic door opening or just a static door opening? 123nabilben123 499 — 5y
0
Dynamic. Epicyoutube65 -5 — 5y

Answer this question