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

Why does my script have this error?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
0
Answered by
Bman8765 270 Moderation Voter
9 years ago

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!

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. TroytheDestroyer 75 — 9y
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...) Redbullusa 1580 — 9y
Ad

Answer this question