How would I make all the parts in this sliding-door-script move simultaneously?
Right now, it moves the parts one-by-one, which is not what I want it to do...
I want the parts to move simultaneously so that it looks like a real-life sliding door.
My current coding is as follows:
local Sensor = script.Parent.Sensor.Part local Door1 = script.Parent.Door1 doorClosed = true Sensor.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then if doorClosed then doorClosed = false for i,v in ipairs(Door1:GetChildren()) do for i = 1,30,1 do v.CFrame = CFrame.new(v.Position + Vector3.new(-0.2,0,0)) wait() end end end end end)
Any help is greatly appreciated!
If you want them to move completely asynchronously, use the spawn function.
local Sensor = script.Parent.Sensor.Part local Door1 = script.Parent.Door1 doorClosed = true Sensor.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") if hum then if doorClosed then doorClosed = false for i,v in ipairs(Door1:GetChildren()) do spawn(function() for i = 1,30,1 do v.CFrame = CFrame.new(v.Position + Vector3.new(-0.2,0,0)) wait() end end) end end end end)
Made in the ScriptingHelpers, so no guarentees you will be able to copy this code directly, although it should work.