How would i make a script like this work?

Im trying to make a pretty simple door script.
I want to make it so when the door is clicked, it goes to a location and when it is clicked again, it goes back.

This is my script so far:

local Door = script.Parent
local Opened = 0

function OnTouch(hit)
			Opened = 1
		if Opened == 1 then
		Door.Position = Vector3.new(-16.112, 5.95, -3.512)
		Door.Orientation = Vector3.new(0, 180, -90)
		Opened = 2
		wait(0.5)
		
		end		
end	

This script is not complete because i am quite stumped. If there are any alternative methods, please tell me!

Click Dectors are the easiest way to do this ClickDetector | Roblox Creator Documentation

Here is a simple door script that alternates between being closed and opening 90 degrees inwards.

local Door = script.Parent
local Opened = false

local ClosedCFrame = Door.CFrame

local OpenedCFrame = Door.CFrame * CFrame.new(Door.Size.X/2,0,Door.Size.X/2) * CFrame.Angles(0,math.rad(90),0)

local function OpenDoor()
	if Opened then
		Opened = false
		Door.CFrame = ClosedCFrame
	else
		Opened = true
		Door.CFrame = OpenedCFrame
	end
end
script.Parent.ClickDetector.MouseClick:Connect(OpenDoor)

Sorry had to respost cause I accidently replied to someone elses comment lol, but hopefuly this works

local debounce = false
local CoolDownTime = 1 -- The time you must wait before you can open adn close the door again
function OnTouch(hit)
	Opened = false
	if not Opened and not debounce then
		Opened = true
		debounce = true
		Door.Position = Vector3.new(The position of the opened door)
		Door.Orientation = Vector3.new(The orientation of the opened door)
		wait(CoolDownTime)
		debounce = false
	elseif Opened and not debounce then
		debounce = true
		Opened = false
		Door.Position = Vector3.new(The position of the closed door)
		Door.Orientation = Vector3.new(The orientation of the closed door)
		wait(CoolDownTime)
		debounce = false
	end		
end	

script.Parent.Touched:Connect(OnTouch)

Yep, you’re right. And on top of that, you also need a method to check whether the door is open or not. Here’s the script I improvised: (Insert a ClickDetector into your door, assuming it’s a part. This won’t work on models)

local opened = false
local openPosition = CFrame.new(0, 0, 0) -- Change these to the positions of your doors.
local closedPosition = CFrame.new(0, 0, 0) -- Also use CFrame because it also changes rotation unlike Vectors

script.Parent.ClickDetector.MouseClick:Connect(function()
    if opened == false then
        opened = true
        script.Parent.CFrame = openPosiiton
    else
        opened  = false
        script.Parent.CFrane = closedPosition
    end
end)

Thanks!

local Door = script.Parent
local opened = false
local openPosition = CFrame.new(-15.388, 5.65, -3.288) * CFrame.Angles(math.rad(0), math.rad(180), math.rad(-90)) 
local closedPosition = CFrame.new(-18.888, 5.65, -6.488) * CFrame.Angles(math.rad(0),math.rad(90), math.rad(-90))

Door.ClickDetector.MouseClick:Connect(function()
	if opened == false then
		opened = true
		script.Parent.CFrame = openPosition
	else
		opened  = false
		script.Parent.CFrame = closedPosition
	end
end)

i understand everything except the “math.rad” part. I watched a video on it, but im still confused about it