function onTouched(hit)
script.Parent.Parent.Door1.Velocity = -5, 0, 0
script.Parent.Parent.Door2.Velocity = 5, 0, 0
wait(1)
script.Parent.Parent.Door1.Velocity = 0, 0, 0
script.Parent.Parent.Door2.Velocity = 0, 0, 0
wait(5)
script.Parent.Parent.Door1.Velocity = 5, 0, 0
script.Parent.Parent.Door2.Velocity = -5, 0, 0
wait(1)
script.Parent.Parent.Door1.Velocity = 0, 0, 0
script.Parent.Parent.Door2.Velocity = 0, 0, 0
end
connection = script.Parent.Touched:connect(onTouched)
COMMUNITY QUESTION
I need help to fix this sliding door script?
4 answers
function onTouched(hit)
script.Parent.Parent.Door1.Velocity = -5, 0, 0
script.Parent.Parent.Door2.Velocity = 5, 0, 0
wait(1)
script.Parent.Parent.Door1.Velocity = 0, 0, 0
script.Parent.Parent.Door2.Velocity = 0, 0, 0
wait(5)
script.Parent.Parent.Door1.Velocity = 5, 0, 0
script.Parent.Parent.Door2.Velocity = -5, 0, 0
wait(1)
script.Parent.Parent.Door1.Velocity = 0, 0, 0
script.Parent.Parent.Door2.Velocity = 0, 0, 0
end
script.Parent.Touched:connect(onTouched) --Changed this because you don't need the connection thing. Make sure this script is in the brick that is being touched for it to work!
First of all use the Vector3 to set the Velocity of the object, if Vector3 doesn't work then try CFrame
Code:
script.Parent.Parent.Door1.Velocity = Vector3.new(-5, 0, 0)
script.Parent.Parent.Door2.Velocity = Vector3.new(5, 0, 0)
wait(1)
script.Parent.Parent.Door1.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Door2.Velocity = Vector3.new( 0, 0, 0)
wait(5)
script.Parent.Parent.Door1.Velocity = Vector3.new(5, 0, 0)
script.Parent.Parent.Door2.Velocity = Vector3.new(-5, 0, 0)
wait(1)
script.Parent.Parent.Door1.Velocity = Vector3.new(0, 0, 0)
script.Parent.Parent.Door2.Velocity = Vector3.new(0, 0, 0)
Well in order to make a sliding door work well in my opinion you would need to use body movers. We can use BodyPosition with BodyGyro to make two sliding doors open and then close after stepping over a button. I wrote this script for you, put it in the model which contains your two doors and change the names appropriately.
db=false
script.Parent.button.Touched:connect(function(player)
if db then return end
db=true
local h=player.Parent:FindFirstChild("Humanoid") if h~= nil then
door1=script.Parent.d1
door2=script.Parent.d2
door1.Anchored=false
door2.Anchored=false
local z=Instance.new("BodyPosition")
z.Parent=door1
z.position=door1.Position+Vector3.new(5,0,0)
z.maxForce=Vector3.new(100000,100000,100000)
D=2000
local zz=Instance.new(("BodyGyro"))
zz.Parent=door1
zz.maxTorque=Vector3.new(4000,4000,4000)
zz.cframe=CFrame.new(356.44, 168, 174.361)* CFrame.Angles(math.rad(90),math.rad(-90),math.rad(0))
zz.D=500
zz.P=40000
local x=Instance.new("BodyPosition")
x.Parent=door2
x.position=door2.Position+Vector3.new(-5,0,0)
x.maxForce=Vector3.new(100000,100000,100000)
D=2000
local xx=Instance.new(("BodyGyro"))
xx.Parent=door2
xx.maxTorque=Vector3.new(4000,4000,4000)
xx.cframe=CFrame.new(338.44, 168, 174.355)* CFrame.Angles(math.rad(90),math.rad(-90),math.rad(0))
xx.D=500
xx.P=40000
wait(3)
z.position=door1.Position+Vector3.new(-5,0,0)
x.position=door2.Position+Vector3.new(5,0,0)
wait(3)
z.Parent=nil
x.Parent=nil
zz.Parent=nil
xx.Parent=nil
door1.Anchored=true
door2.Anchored=true
db=false
end
end)
You all over-complicate it. If it were me, I'd just use CFrame, and if that's what you're looking for I'd have something like this-
local door = script.Parent
function Open()
for i = 1, door.Size.X * 10 do
door.CFrame = door.CFrame + Vector3.new(.1, 0, 0)
wait()
end
wait(3)
for i = 1, door.Size.X * 10 do
door.CFrame = door.CFrame - Vector3.new(.1, 0, 0)
wait()
end
end
function Touched(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Open()
end
end
door.Touched:connect(Touched)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
I steal can't get it working
What is the error? Or what is going wrong?
Actually the
connectmethod returns aRBXScriptConnectionso you can have a variable for it. That's not what would've been causing any problems with his script.