Door needs to move faster than it is moving

Hello all!
My door script works when a player touches it, just it happens to move really slow to its correct coordinates and then moves back slowly.
Is there a way I can make it move faster.


script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
   	if debounce == false then
   		debounce = true
   		for x = 1, 41 do
   			wait(.1)
   			script.Parent.CFrame  = script.Parent.CFrame + Vector3.new(0,0,.1)
   		end
   		wait(3)
   		for x = 1, 41 do
   			wait(.1)
   			script.Parent.CFrame  = script.Parent.CFrame + Vector3.new(0,0,-.1)
   		end
   		debounce = false
   	end
   end
end)

change the wait(0.1) to a lower number if you want it faster.

Just saying, but you might want to tween the doors and not loop through all that as it is way smoother and less expensive as well.

use TweenService to make it smoother and customize more things

script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
   	if debounce == false then
   		debounce = true
   		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {CFrame = script.Parent.CFrame + Vector3.new(0,0,4.1)}):Play()
   		wait(3)
   		game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(1), {CFrame = script.Parent.CFrame + Vector3.new(0,0,-4.1)}):Play()
   		debounce = false
   	end
   end
end)
1 Like

I am not super familiar with the Tween Service, can you provide me a little explanation about it?

sure, you can find info in dev hub

Thanks a bunch for it guys. Really appreciate the feedback!

1 Like