Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
nanaluk01 247 Moderation Voter
7 years ago

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!

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. OldPalHappy 1477 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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.

0
That's an option, I guess. OldPalHappy 1477 — 7y
0
Fix the tabs please. :c awfulszn 394 — 7y
Ad

Answer this question