Well this script is suppose to get the children of the model and determine if they are parts or not, and if they are, when clicked it will move thing accordingly. But it isn't working, what did I do wrong?
Here is the script:
open = false
p = script.Parent:GetChildren()
wait()
function onClicked()
if script.Parent.OPEND.Value == 1 then
if open == false then
local cfr = p.CFrame
open = true
for i = 0,1.5,0.1 do
if p[i]:IsA("Part") then
wait(0.1)
p[i].CFrame = p[i].CFrame*CFrame.fromEulerAnglesXYZ(0,-0.1,0)*CFrame.new(0.01,0,-0.25)
end
p[i].CFrame = cfr*CFrame.fromEulerAnglesXYZ(0,-math.pi/2,0)*CFrame.new(-2.5,0,-2.5)
open = false
script.Parent.OPEND.Value = 0
end
elseif script.Parent.OPEND.Value == 0 then
if open == false then
local cfr = p.CFrame
open = true
for i = 0,1.5,0.1 do
if p[i]:IsA("Part") then
wait(0.1)
p[i].CFrame = p[i].CFrame*CFrame.fromEulerAnglesXYZ(0,0.1,0)*CFrame.new(-0.01,0,0.25)
end
p[i].CFrame = cfr*CFrame.fromEulerAnglesXYZ(0,math.pi/2,0)*CFrame.new(-2.5,0,2.5)
open = false
script.Parent.OPEND.Value = 1
end
end
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
