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

How would I make all the parts in this sliding-door-script move simultaneously?

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!

1 comment

0

Remove the wait. If you want the door to be animated, I think you have to move the for loop outside the pairs loop and move the wait outside the pairs loop as well.

1 answer

✓ Accepted answer

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.

2 comments

0

That's an option, I guess.

0

Fix the tabs please. :c

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