"Attempt To Call Nil Value", error in loop script

I’m currently trying to make a simple on/off light source, but the thing is when I press the button it pops up with the error…

Workspace.Part.Script:8: attempt to call a number value

I’m unsure on what this means and am a bit confused…?

Code:

local Part = game.Workspace.Part1

local clickDetector = script.Parent.ClickDetector

local Light = Part.SpotLight

function onMouseClick()

Light.Enabled = true

for brightness = 0.1, 1, 0.1 do

Light.Brightness(brightness)

wait(0.05)

end

end

clickDetector.MouseClick:connect(onMouseClick)

Change it to this:

for brightness = 0.1, 1, 0.1 do

Light.Brightness = brightness

wait(0.05)

end
1 Like