local isOn = true
script.Parent.MouseButton1Click:Connect(function()
if isOn then
script.Parent.Text = “Off”
game.Lighting.GlobalShadows = false
elseif not isOn then
script.Parent.Text = “On”
game.Lighting.GlobalShadows = true
end
end)
The problem with your script is that you never change the variable when you turn global shadows on or off.
I suggest you make a BoolValue under your Gui Button, to determine whether Global Shadows is on or off.
Insert a BoolValue under your Gui Button, and rename it to isOn. Then, use the following code below:
local Lighting = game:GetService("Lighting")
local Btn = script.Parent
local isOn = Btn:WaitForChild("IsOn")
Btn.Activated:Connect(function()
if isOn.Value then
Btn.Text = "Off"
Lighting.GlobalShadows = false
isOn.Value = false -- You needed to add this
elseif not isOn.Value then
Btn.Text = "On"
Lighting.GlobalShadows = true
isOn.Value = true -- you needed to add this as well
end
end)
local Game = game
local Script = script
local Lighting = Game:GetService("Lighting")
local Button = Script.Parent
local function OnActivated()
Lighting.GlobalShadows = not Lighting.GlobalShadows
Button.Text = if Lighting.GlobalShadows then "On" else "Off"
end
Button.Activated:Connect(OnActivated)
You don’t actually need a ValueObject to track state, you can use the property’s value itself.
Yes your script can also work, but let’s say if @PowerlessFruit wants the settings to save when a player leaves, it would be much easier to save those settings with a Value Object. I believe it’s better to use a Value Instance rather than checking the property’s value for this kind of system. Or, you can do both at the same time.
Also @PowerlessFruit , I believe the solution should go to my first post as I was the first one to give a solution and the first one to have a working solution. As well, it explains the issue you were facing and gives a brief explanation on a fix. It can help other people who could be facing a similar issue.