for i = y, -ySize, -0.1 do
script.Parent.Door.Position = Vector3.new(x, i, z)
wait(0.01)
print(ySize)
end
wait(1)
for i = -y, ySize, 0.1 do
script.Parent.Door.Position = Vector3.new(x, i, z)
wait(0.01)
print(ySize)
end
You should add a debounce. In the video, you’re trying to open the door while it’s already opening/closing. This causes the functions to conflict as they couldn’t agree on what position the door should be.
Also, you should consider using TweenService for the door animation instead of running for loops.
Try this:
x = script.Parent.Door.Position.X
y = script.Parent.Door.Position.Y
z = script.Parent.Door.Position.Z
ySize = script.Parent.Door.Size.Y / 2
local moving = false
workspace.Button.ClickDetector.MouseClick:Connect(function()
if not moving then --if the door isn't already moving then animate the door
moving = true --set "moving" to true so that future calls to open the door will be blocked
for i = y, -ySize, -0.1 do
script.Parent.Door.Position = Vector3.new(x, i, z)
wait(0.01)
print(ySize)
end
wait(1)
for i = -y, ySize, 0.1 do
script.Parent.Door.Position = Vector3.new(x, i, z)
wait(0.01)
print(ySize)
end
moving = false --set "moving" to false as now the door is done animating and is no longer moving
end
end)