|
| 01 Apr 2012 03:14 AM |
Hey guys, I have a door and when you click the button it goes up, and when you click it again it goes down. How can I make it so it does the opposite and stays up, and when you press it it goes down?
The script is pretty long, sorry about that.
local d = script.Parent.Door local origin = d.CFrame.y local b = {} for _,v in pairs(script.Parent:GetChildren()) do if ((v.className == "Part") and (v.Name == "Button")) then table.insert(b,v) end end
local active = false local pos = 0
function moveDoor(dir) if (dir == 0) then for i = d.CFrame.y,origin,-0.1 do d.CFrame = CFrame.new(d.CFrame.x,i,d.CFrame.z) wait() end d.CFrame = CFrame.new(d.CFrame.x,origin,d.CFrame.z) else local mth = ((d.CFrame.y+(d.Size.y/2))+(d.Size.y/2-1)) for i = origin,((d.CFrame.y+(d.Size.y/2))+(d.Size.y/2-1)),0.1 do d.CFrame = CFrame.new(d.CFrame.x,i,d.CFrame.z) wait() end d.CFrame = CFrame.new(d.CFrame.x,mth,d.CFrame.z) end end
function setup() for _,v in pairs(b) do v.Click.MouseClick:connect(function() if (active) then return end active = true if (pos == 0) then pos = 1 else pos = 0 end moveDoor(pos) active = false end) end end
setup() |
|
|
| Report Abuse |
|