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

Please can I have help with a CFrame door and :getChildren?

Asked by
Nidoxs 190
9 years ago

So what happens is, when I test/play the game the Door (Model, inside of ["Cframe door"] inside of Workspace, dissapears and all I am left with is the button. Before I edited it it was a single part it worked but I wanted a couple of parts to move with each over. But I am struggling to do this. Please can you help me?

Speed = 0.5 -- Speed at which the door rises. Higher = faster. 
Time = 5 -- Time between the door totally open and starting to close.
Running = false
for x,z in pairs(script.Parent.Parent.Parent:getChildren()) do
if z.Name == "Button" then
z.CD.MouseClick:connect(function ()
if Running == true then return end
Running = true
local D = script.Parent.Parent:getChildren()
for i=1,D.y/Speed*10+1 do 
D.CFrame = D.CFrame*CFrame.new(0,0.1*Speed,0)
wait()
end 
wait(Time)
for i=1,D.y/Speed*10+1 do 
D.CFrame = D.CFrame*CFrame.new(0,-0.1*Speed,0)
wait()
end 
Running = false
end)
end
end 

2 answers

Log in to vote
0
Answered by
SirGory 15
9 years ago

I can only spot that :getChildren()might have to be changed to either :GetChildren() or :children()

Ad
Log in to vote
0
Answered by
hiccup111 231 Moderation Voter
9 years ago

There was a few little nicks in the script, like on lines 10 and 15 - it was attempting to get the 'y' Size axis of a Table (line 09, 'D').

This script should work - although, if you want each part of the door to go up/down synchronously, please use the second script.

Speed = 0.5 -- Speed at which the door rises. Higher = faster. 
Time = 5 -- Time between the door totally open and starting to close.
Running = false
for x,z in pairs(script.Parent.Parent:GetChildren()) do
    if z.Name == "Button" then
        z.CD.MouseClick:connect(function ()
            if Running == true then return end
            Running = true
            for _,D in pairs(script.Parent.Parent:GetChildren()) do
                if D:IsA("BasePart") then
                    for i=1,D.Size.y/Speed*10+1 do 
                        D.CFrame = D.CFrame*CFrame.new(0,0.1*Speed,0)
                        wait()
                    end
                end
            end
                wait(Time)
            for _,D in pairs(script.Parent.Parent:GetChildren()) do
                if D:IsA("BasePart") then
                    for i=1,D.Size.y/Speed*10+1 do 
                        D.CFrame = D.CFrame*CFrame.new(0,-0.1*Speed,0)
                        wait()
                    end
                end
            end
            Running = false
        end)
    end
end 

Synchronous Movement:

Speed = 0.5 -- Speed at which the door rises. Higher = faster. 
Time = 5 -- Time between the door totally open and starting to close.
Running = false
for x,z in pairs(script.Parent.Parent:GetChildren()) do
    if z.Name == "Button" then
        z.CD.MouseClick:connect(function ()
            if Running == true then return end
            Running = true
            for _,D in pairs(script.Parent.Parent:GetChildren()) do
                if D:IsA("BasePart") then
                    coroutine.resume(coroutine.create(function()
                        for i=1,D.Size.y/Speed*10+1 do 
                            D.CFrame = D.CFrame*CFrame.new(0,0.1*Speed,0)
                            wait()
                        end
                    end))
                end
            end
                wait(Time)
            for _,D in pairs(script.Parent.Parent:GetChildren()) do
                if D:IsA("BasePart") then
                    coroutine.resume(coroutine.create(function()
                        for i=1,D.Size.y/Speed*10+1 do 
                            D.CFrame = D.CFrame*CFrame.new(0,-0.1*Speed,0)
                            wait()
                        end
                    end))
                end
            end
            Running = false
        end)
    end
end 

Quick Tutor: 'coroutines' - basically allow you to run multiple things at once, like two while loops at the same time.

More Information link: http://wiki.roblox.com/index.php?title=Coroutine_Tutorial http://wiki.roblox.com/index.php?title=Coroutine http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines

Answer this question