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)
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)