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
I can only spot that :getChildren()
might have to be changed to either :GetChildren()
or :children()
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