Need help with settings script

I’m writing a settings script, where if you click the parent of the script (button), it toggles Global Shadows.

The script only works until the “elseif” statement.

I tried seperating the if statement into two singular if statements, instead of using elseif, that didn’t do anything tho.
In the Output, there were also no warnings or anything regarding the script.

The script:

local button = script.Parent
local Lighting = game:GetService("Lighting")

local Activated = true

if Activated == true then
    button.MouseButton1Click:Connect(function()
        Lighting.GlobalShadows = false
        
        Activated = false
    end)
elseif Activated == false then
    button.MouseButton1Click:Connect(function()
        Lighting.GlobalShadows = true
        
        Activated = true
    end)
end

Any help is greatly appreciated, thanks! :slight_smile:
PS: This is my first topic, so I’m open to receive feedback on what I could do better next time!

1 Like

Keep in mind that Activated is being compared to a boolean in the if statement by the script as soon as possible and then never again. If you want to make is so it’s checked every time when a button is clicked, move the if statement to the events, like this:

button.MouseButton1Click:Connect(function()
	if Activated == true then
		Lighting.GlobalShadows = false
		Activated = false
	end
end)
2 Likes

Alright, thanks, I will try that asap! If it works, I’ll mark your answer as the solution! :slight_smile:

1 Like

Aaaaaaaaand… it works! Thanks alot, Spider12PL!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.