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

Why does my script have this error?

I'm making a plugin to disable/enable global shadows. I cut off the plugin part so that people won't steal. Here is my script:

button.Clicked:connect(function()
local lighting = game.Lighting
lighting.GlobalShadows = true
elseif lighting.GlobalShadows == true then
lighting.GlobalShadows = false
end
end)

the problem is it underlines elseif in red and says that it needs an end to close the function at line 8 (1 in this script). I put 2 ends (as you see). But it still says that it needs an end. I added like 100 ends but it still underlines elseif in red. Could anyone fix this? Thanks for reading!

1 answer

Correct me if I'm wrong but I'm pretty sure you need an If statement before you can write elseif Try this:

button.Clicked:connect(function()
	if lighting.GlobalShadows == false then
		local lighting = game.Lighting
		lighting.GlobalShadows = true
	elseif lighting.GlobalShadows == true then
		lighting.GlobalShadows = false
	end
end)

If this helped make sure to accept the answer! if this didn't help, comment on it so I can attempt to figure out the problem!

2 comments

0

I deleted line 3 and put it into line 2 and made the previous line 2 to line 3. When I uploaded it, it showed up, but when I clicked it did nothing. I went back and did it your way but nothing happened.

0

You should set the 'lighting' variable to global if you're going to use it on the 'if' and 'elseif' statement. Otherwise, add another 'lighting' and its assignment under 'elseif' and write out the whole name for 'lighting' in the 'if' and 'elseif' statement (game.Lighting.GlobalShadows...)

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