Turn off all shadow's from all Lightings

So I am trying to make a Remove All Shadow’s GUI Button for my game and when player clicks it all shadow’s will be off but for some reason the Light’s in the game won’t be turned shadow’s off and I am not sure what’s wrong with the script please help.

local shadows = script.Parent.Shadows

shadows.MouseButton1Click:Connect(function()
if game.Lighting.GlobalShadows == false then
shadows.Text = ‘Shadows - On’
game.Lighting.GlobalShadows = true
game.Lighting.Ambient = Color3.new(0, 0, 0)
game.Lighting.Brightness = 0.5

	-- Turn off shadows from all lights
	for _, descendant in pairs(workspace:GetDescendants()) do
		if descendant:IsA('Light') then
			if descendant:IsA('PointLight') or descendant:IsA('SpotLight') or descendant:IsA('SurfaceLight') then
				descendant.Shadows = false
				descendant.Enabled = false
				descendant.Enabled = true
			end
		end

		-- Turn off shadows from all lights inside of models
		if descendant:IsA('Model') then
			for _, modelDescendant in pairs(descendant:GetDescendants()) do
				if modelDescendant:IsA('Light') then
					modelDescendant.Shadows = false
					modelDescendant.Enabled = false
					modelDescendant.Enabled = true
				end
			end
		end
	end


else
	shadows.Text = 'Shadows - Off'
	game.Lighting.GlobalShadows = false
	game.Lighting.Ambient = Color3.new(0.5, 0.5, 0.5)
	game.Lighting.Brightness = 1

	-- Turn on shadows from all lights
	for _, descendant in pairs(workspace:GetDescendants()) do
		if descendant:IsA('Light') then
			if descendant:IsA('PointLight') or descendant:IsA('SpotLight') or descendant:IsA('SurfaceLight') then
				descendant.Shadows = true
				descendant.Enabled = false
				descendant.Enabled = true
			end
		end

		-- Turn on shadows from all lights inside of models
		if descendant:IsA('Model') then
			for _, modelDescendant in pairs(descendant:GetDescendants()) do
				if modelDescendant:IsA('Light') then
					modelDescendant.Shadows = true
					modelDescendant.Enabled = false
					modelDescendant.Enabled = true
				end
			end
		end
	end
end

end)

1 Like

From what I know Shadows Is not part of light, try replacing it with CastShadow

Also, don’t use game.Lighting, instead use game:GetService(“Lighting”)
Also, you don’t have to do

if game.Lighting.GlobalShadows.Enabled == false then

You can do

if not game.Lighting.GlobalShadows then
1 Like

Shadows Is a property of a light.

please format your code correctly using three backtics:

local shadows = script.Parent.Shadows

shadows.MouseButton1Click:Connect(function()
if game.Lighting.GlobalShadows == false then
shadows.Text = ‘Shadows - On’
game.Lighting.GlobalShadows = true
game.Lighting.Ambient = Color3.new(0, 0, 0)
game.Lighting.Brightness = 0.5

	-- Turn off shadows from all lights
	for _, descendant in pairs(workspace:GetDescendants()) do
		if descendant:IsA('Light') then
			if descendant:IsA('PointLight') or descendant:IsA('SpotLight') or descendant:IsA('SurfaceLight') then
				descendant.Shadows = false
				descendant.Enabled = false
				descendant.Enabled = true
			end
		end

		-- Turn off shadows from all lights inside of models
		if descendant:IsA('Model') then
			for _, modelDescendant in pairs(descendant:GetDescendants()) do
				if modelDescendant:IsA('Light') then
					modelDescendant.Shadows = false
					modelDescendant.Enabled = false
					modelDescendant.Enabled = true
				end
			end
		end
	end


else
	shadows.Text = 'Shadows - Off'
	game.Lighting.GlobalShadows = false
	game.Lighting.Ambient = Color3.new(0.5, 0.5, 0.5)
	game.Lighting.Brightness = 1

	-- Turn on shadows from all lights
	for _, descendant in pairs(workspace:GetDescendants()) do
		if descendant:IsA('Light') then
			if descendant:IsA('PointLight') or descendant:IsA('SpotLight') or descendant:IsA('SurfaceLight') then
				descendant.Shadows = true
				descendant.Enabled = false
				descendant.Enabled = true
			end
		end

		-- Turn on shadows from all lights inside of models
		if descendant:IsA('Model') then
			for _, modelDescendant in pairs(descendant:GetDescendants()) do
				if modelDescendant:IsA('Light') then
					modelDescendant.Shadows = true
					modelDescendant.Enabled = false
					modelDescendant.Enabled = true
				end
			end
		end
	end
end
end)

Anyways, try removing

and