Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make this "moving door " script not so choppy?

I made this moving door script but the movement of the door seems too unrealistic: it doesn't slide it just teleports itself small distances, how can I make it to look more natural while maintaining the speed? It also doesn't work with unions I don't know why:

local buttonPressed = false
local wall = script.Parent.Parent.wall:GetChildren()
local dis =150


script.Parent.Touched:connect(function(part) 
    if not buttonPressed and part.Parent:findFirstChild("Humanoid", true) then
        buttonPressed = true
        script.Parent.BrickColor = BrickColor.new(21)
		for i=0, dis do	    
			for i, v in pairs(wall)  do
				if v:IsA("Part") or v:IsA("Union")  then
	            	v.CFrame = v.CFrame + Vector3.new(0,0,0.1)
	            	wait()
				end
			end
		end
        		wait(5)
        		for i=0, dis do
					for i, v in pairs(wall)  do
						if v:IsA("Part") or v:IsA("Union") then
							v.CFrame = v.CFrame + Vector3.new(0,0,-0.1)
            				wait()
						end
					end 
        		end
        wait(5)
        script.Parent.BrickColor = BrickColor.new(309) 
        buttonPressed = false
    end
end)


1 comment

0

try "for i = 1, 16 do," and then experiment with your cframe values until it works the way you like it. This is the for loop I use for all my doors.

1 answer

Here is an example of my suggestion above.

The CFrame values are not perfect but if you place this in a part and and run the code you will see that it is smooth.

I hope I helped.

code:

local open = false
local door = script.Parent

cframe = door.CFrame
script.Parent.ClickDetector.MouseClick:connect(function()
	if open == false then
		open = true
		for i = 1,16 do
			wait()
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-0.022,0,-.181) * CFrame.fromEulerAnglesXYZ(0,0.090,0)	
		end
	elseif open == true then
		open = false
		for i = 1, 16 do
			wait()
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0.022,0,.181) * CFrame.fromEulerAnglesXYZ(0,-0.090,0)
		end
		door.CFrame = cframe -- this returns the door to it's original cframe. Useful if the door glitched when closing.
	end
end)

1 comment

0

I should have specified, that the script above (the one I provided) works smoothly with single parts but when moving a model it looks horribly choppy

This discussion is preserved as it was. New answers, comments, and votes are closed.