Hello, I am trying to create a door that will go up when a Key touches it, but I don’t know how to make it go smooth.
I tried using wait(0.1) to make it go up, but it is really buggy.
My script:
local waitTime = Instance.new("BoolValue") -- creates a value if you can open the door.
waitTime = false -- set to false so they can open the door.
script.Parent.Touched:Connect(function(hit) -- when the key touches the door.
if hit.Parent.Name == "Key" and waitTime == false then -- if the key touched it and the boolValue is false then it will go through.
waitTime = true
script.Parent.CFrame = CFrame.new(0,5.1,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.2,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.3,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.4,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.5,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.6,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.7,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.8,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,5.9,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.1,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.2,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.3,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.4,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.5,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.6,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.7,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.8,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,6.9,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.1,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.2,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.3,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.4,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.5,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.6,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.7,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.8,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,7.9,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.1,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.2,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.3,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.4,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.5,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.6,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.7,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.8,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,8.9,0)
wait(0.1)
script.Parent.CFrame = CFrame.new(0,9,0)
else
wait(10)
waitTime = false
script.Parent.CFrame = CFrame.new(0,0,0)
end end)
I searched in the Developer Hub on how can I create a smooth CFrame movement and also in other topics but they’re not very helpful.