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

Why am I getting this error?

Asked by 9 years ago

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)

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago
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.

Ad

Answer this question