Turning on and off shadows with a button

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    When you press a button shadows will turn on/off.
  2. What is the issue? Include screenshots / videos if possible!
    The shadow’s won’t turn on or off when pressing the button.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried so far looking it up on the web. Only found a dev post but it looks like the same thing as mine. Not sure what to do.
local GlobalShadows = game.Lighting.GlobalShadows
local DisabledShadowButton = script.Parent.Shadows.DisableShadows
local EnableShadowsButton = script.Parent.Shadows.EnableShadows

DisabledShadowButton.MouseButton1Click:Connect(function()
	GlobalShadows = false
end)

EnableShadowsButton.MouseButton1Click:Connect(function()
	GlobalShadows = true
end)
2 Likes

How would I add each part to a script…

Just checked, you should be able to set Global shadows to false using that.

Your issue is that you’re defining your variable GlobalShadows as the direct value of “GlobalShadows” under lighting, which is either a true or false value, you’re not defining it.

Try to directly set game.Lighting.GlobalShadows instead.

What would I set for the Shadows variable tho…

I kind of understand wat u mean…

local DisabledShadowButton = script.Parent.Shadows.DisableShadows
local EnableShadowsButton = script.Parent.Shadows.EnableShadows

DisabledShadowButton.MouseButton1Click:Connect(function()
	game.Lighting.GlobalShadows = false
end)

EnableShadowsButton.MouseButton1Click:Connect(function()
	game.Lighting.GlobalShadows = true
end)

Adding on to what Sekuriyo said, this is how you would write it.

local lighting = game.Lighting
local DisabledShadowButton = script.Parent.Shadows.DisableShadows
local EnableShadowsButton = script.Parent.Shadows.EnableShadows

DisabledShadowButton.MouseButton1Click:Connect(function()
	lighting.GlobalShadows = false
end)

EnableShadowsButton.MouseButton1Click:Connect(function()
	lighting.GlobalShadows = true
end)

This is an easy fix, i’ll brb with a code…

Ok… I think I kind of understand it. Someone on another post said something similar to that. I think I kind of understand it.

Could you send a screenshot of the GUI name and location?

@DeveloperCoolBoi you can use this script.

Wait, fixed it. Let me show a script

1 Like

``lua
Lighting = game.Lighting
DisabledShadowButton.MouseButton1Click:Connect(function()

Lighting.GlobalShadows = false

end)

EnableShadowsButton.MouseButton1Click:Connect(function()

Lighting.GlobalShadows = true

end)

1 Like

Done! Thx for the help. It’s working!

This is the same script, you’ve just declared a variable for the ‘Lighting’ service.

No, this script is not the same, this time I declared a variable for lighting and changed the GlobalShadows property. OP’s script got the value of the GlobalShadows property in the first line.

I’m stating that it’s the same script as the one provided here.

Oh yeah, he edited it to have the script. The message used to say something else.

Oh my bad, I thought you had just copied their script.

1 Like