Help with turning off shadows

Hello, im trying to create a settings UI where you can turn shadows off or on.
I created a script so that when you click on the toggle shadows button, it will check to see if shadows are on, if so, they will turn off, etc.

I haven’t found the problem to why this isn’t working but I’ve tried different ways to turn the global shadows off.

game.Lighting.GlobalShadows = false

game.Lighting.GlobalShadows.Visible = false

game.Lighting.GlobalShadows.Enabled = false

I’ve tried all these but they aren’t working.

local GUI = script.Parent
local SettingsFrame = GUI:WaitForChild("Settings")
local Buttons = SettingsFrame.List

Buttons.Shadows.BTN.MouseButton1Click:Connect(function()
	if game.Lighting.GlobalShadows == true then
		game.Lighting.GlobalShadows = false
		Buttons.Shadows.BTN.Text = "OFF"
		Buttons.Shadows.BTN.BackgroundColor3 = OffColor
	elseif game.Lighting.GlobalShadows == false then
		game.Lighting.GlobalShadows = true
		Buttons.Shadows.BTN.Text = "ON"
		Buttons.Shadows.BTN.BackgroundColor3 = OnColor
	end
end)
1 Like

Make sure the script is local. Apart from that I see no problem with the script.

1 Like

It is a local script in the ScreenGUI

1 Like

Any errors with your script in the output?

1 Like

Nothing, I have no idea why it isn’t working.

1 Like

Try this maybe:

local lighting = game:GetService("Lighting")

local SettingsFrame = GUI:WaitForChild("Settings")
local shadowsOff = false

local function changeShadows()
	if not shadowsOff then
		shadowsOff = true
		
		lighting.GlobalShadows = false
		
		Buttons.Shadows.BTN.Text = "OFF"
		Buttons.Shadows.BTN.BackgroundColor3 = OffColor
	else
		shadowsOff = false
		
		lighting.GlobalShadows = true
		
		Buttons.Shadows.BTN.Text = "ON"
		Buttons.Shadows.BTN.BackgroundColor3 = OnColor
	end
	
end

Buttons.Shadows.BTN.Activated:Connect(changeShadows)
3 Likes

Heres my full script


-- Variables --

local GUI = script.Parent

-- Client --

----- Shop ------
local ShopFrame = GUI:WaitForChild("Shop")
local SettingsFrame = GUI:WaitForChild("Settings")

------ Settings ------

local Buttons = SettingsFrame.List

local OnColor = Color3.fromRGB(0, 177, 2)
local OffColor = Color3.fromRGB(206, 72, 72)

-- Shadows --
Buttons.Shadows.BTN.MouseButton1Click:Connect(function()
	if game.Lighting.GlobalShadows == true then
		game.Lighting.GlobalShadows = false
		Buttons.Shadows.BTN.Text = "OFF"
		Buttons.Shadows.BTN.BackgroundColor3 = OffColor
	elseif game.Lighting.GlobalShadows == false then
		game.Lighting.GlobalShadows = true
		Buttons.Shadows.BTN.Text = "ON"
		Buttons.Shadows.BTN.BackgroundColor3 = OnColor
	end
end)

1 Like

It works, I guess I was missing a part to get lighting service? Idk but thanks

3 Likes