Error: Error : Workspace.Part.Script:4: bad argument #1 to '?' (CFrame expected, got nil) 14:09:48.793 - Script 'Workspace.Part.Script', Line 4 14:09:48.793 - Stack End
local light = game.Workspace.BMX3.Pan:GetChildren() function touch() for i = 1,100 do light.CFrame = light.CFrame * CFrame.fromEulerAnglesXYZ(0,0.3,0) wait() end wait(2) for e =1, 100 do light.CFrame = light.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.3,0) wait() end end script.Parent.ClickDetector.MouseClick:connect(touch)
local lights = game.Workspace.BMX3.Pan:GetChildren() --this returns a table for _,light in pairs(lights) do if light:isA("BasePart") then function touch() for i = 1,100 do light.CFrame = light.CFrame * CFrame.fromEulerAnglesXYZ(0,0.3,0) wait() end wait(2) for e =1, 100 do light.CFrame = light.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.3,0) wait() end end script.Parent.ClickDetector.MouseClick:connect(touch) end end
You were declaring light as a table not an instance, I used a for loop to get the instances from that table for you.