Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can't change brightness of Pointlight?

So, I'm completely new to Lua, and have almost no clue what I am doing, but I'm trying my best to learn it. I'm trying to turn a PointLight off at the start of the game by changing the values of the Brightness. I know I can just uncheck Enable in the PointLight settings, but I want to use this light later to do the opposite effect, making it slowly fade to being bright again.

local light = script.Parent

---------------------------------

function turnoff()
	for light = 0, 1, 0.5  do 
		light.Brightness = 4.16
		wait(0.5)
		light.Brightness = 0
		print ("Off")
	end
end

---------------------------------

wait(15)

turnoff()

The problem is, when I run the game, I get an error that says " Workspace.void light.Part.PointLight.Script:7: attempt to index number with 'Brightness' ". I've been trying to do something as simple as this for 2 days now, and can't find any help with google. Thanks.

2 answers

✓ Accepted answer

It's because you defined another variable and named it "light" in the for loop. The Lua thinks you meant for the index in your for loop. So change the index name on the for loop to make it work! Also, indexes have no brightness property, that's why the error was occurred.

Consider changing the line 6 to (keep the light variable the same name):

for index = 0, 1, 0.5 do

1 comment

0

Thanks so much, I can't believe it was that simple of a fix

Unlike Python, there's no such local scope here. simply change the index either in the for loop or the variable.

This discussion is preserved as it was. New answers, comments, and votes are closed.