This should work, with a few nuances.
First, you should use CFrame instead of Position.
When you set Position of an object, it makes sure there's open space for it. If not, it sets the object where there is open space (looking upward).
CFrame ignores that requirement and moves the object anyway.
You can make a CFrame using a Vector3, or just by giving it the x, y, and z coordinates.
However since CFrame also describes rotation, it would be better to make this all relative.
First, your script using a variable to make it relative to where the door starts (no more having to know exactly the position of the door!)
local home = workspace.Door.Position
function open()
workspace.Door.Position = home + Vector3.new(0, 4.9, 0)
wait(3)
workspace.Door.Position = home
end
script.Parent.ClickDetector.MouseClick:connect(open)
And now with CFrame:
local home = workspace.Door.CFrame
function open()
workspace.Door.CFrame = home + Vector3.new(0, 4.9, 0)
wait(3)
workspace.Door.CFrame = home
end
script.Parent.ClickDetector.MouseClick:connect(open)
Now there's just the small detail of open being called repeatedly because of multiple clicks. It will shut according to the first click, rather than the most recent one. We can implement something that sort of looks like a debounce to fix this.
local home = workspace.Door.CFrame
local lastPress = nil
function open()
unique = {};
lastPress = unique
workspace.Door.CFrame = home + Vector3.new(0, 4.9, 0)
wait(3)
if lastPress == unique then
workspace.Door.CFrame = home
end
end
script.Parent.ClickDetector.MouseClick:connect(open)