Door event not working

I’m trying to make a vault door that opens and shuts when you click it but the script isn’t working. I’m not surprised and I know I’m doing something wrong so please look at this and point out what the problem is.

local VaultDoor = script.Parent 
 
function clicked()
	if VaultDoor.Positon ~= Vector3(616.433, 104.34, -512.63) then
		VaultDoor.Position = Vector3(616.476, 104.808, -512.665)
	elseif VaultDoor.Position == Vector3(616.476, 104.808, -512.665) then
		VaultDoor.Position = Vector3(611.776, 104.9, -519.421) elseif
		VaultDoor.Position == Vector3(611.776, 104.9, -519.421) then
		VaultDoor.Position = Vector3(616.476, 104.808, -512.665)
	end
end
 
VaultDoor.ClickDetector.MouseClick:Connect(function()
	
end)

You aren’t calling the function, connect the event to it by doing VaultDoor.ClickDetector.MouseClick:Connect(clicked)

I just fixed it nothing happened :confused:

  1. I think you can’t compare vectors directly(use booleans instead and have a vector assigned to each state)
  2. the difference between the vectors above is incredible small for visual changes
  3. you made a typo(it’s Vector3.new(x, y, z))
local VaultDoor = script.Parent 

local open = false 

function clicked()
	open = not open
	if open then 
		VaultDoor.Position = Vector3.new(0, 0, 0) --open position coordinates 
	else 
		VaultDoor.Position = Vector3.new(0, 0, 0) --closed position coordinates 
	end
end

VaultDoor.ClickDetector.MouseClick:Connect(clicked)
  1. I suggest you use TweenService to smoothly animate the door.

Try using cframe.new. An example of this would be this, put the positions inside of the ()s -
VaultDoor.CFrame = CFrame.New()

because you did

:Connect(function()

Which directly creates a function, use

:Connect(clicked)

Thank you! It works and it makes a lot of sense. One thing when it opens it doesn’t go sideways as I intended. Do you know which number of vector3 faces sideways? (if that makes sense)

You can move the door to the position you want it to be, copy the coordinates to paste them in the script and then move it back. You can find an object coordinates in the Object.Position property in the explorer.

I’ve tried that and it moves it but it doesn’t move sideways

local VaultDoor = script.Parent 
local ClickButton = VaultDoor:WaitForChild("ClickDetector")
local isOpen = false

local function clicked()
	if not isOpen then
		isOpen = true
		VaultDoor.CanCollide = false
		VaultDoor.Transparency = 1
	elseif isOpen then
		isOpen = false
		VaultDoor.CanCollide = true
		VaultDoor.Transparency = 0
	end
end

ClickButton.MouseClick:Connect(function(clicked)