A disable blur button isn't working

Hello! I am trying to make a script that turns a blur effect off. (It is stored in lighting) Please debug this script. The script is meant to turn blur on and off when a text button is clicked. (I’m a beginner scripter.)
Thank you for your time!

Script:

     script.Parent.MouseButton1Click:Connect(function()
end)

game.Lighting.Blur.Enabled = false
script.Parent.Text = ("Blur - Off")

else


game.Lighting.Blur.Enabled = true
script.Parent.Text = ("Blur - On")
2 Likes

Any errors in the output? And I need to see your Lighting tab, also you code is not even in the event.

check if the script is local or not
it should be local

Try this code.
Should look like this:

script.Parent.MouseButton1Click:Connect(function()

if script.Parent.Text = "Blur - On" then
game.Lighting.Blur.Enabled = false
script.Parent.Text = "Blur - Off"

else


game.Lighting.Blur.Enabled = true
script.Parent.Text = "Blur = On"
end
end)

The code wouldn’t even run, it would just error then stop.

if the script is a server one(Script) then it would only affect how the server camera sees the things around, but not how the client sees it. If it is a client one(LocalScript) then it would affect how the local player sees but not other players or server. I think that’s what you’re aiming for.

2 Likes

and yes change the code as @seancool07777 suggested his point is also good

I’ve never heard of a “server camera” but what I think you meant is if the server handles it it will affect all players.

Your code:

     script.Parent.MouseButton1Click:Connect(function()
end) -- Needs to be at the bottom of the function
-- Needs to be an if statement, you can't use else without one.
game.Lighting.Blur.Enabled = false
script.Parent.Text = ("Blur - Off")

else


game.Lighting.Blur.Enabled = true
script.Parent.Text = ("Blur - On")

Working code:

     script.Parent.MouseButton1Click:Connect(function()

if game.Lighting.Blur.Enabled == true then
game.Lighting.Blur.Enabled = false
script.Parent.Text = ("Blur - Off")

else


game.Lighting.Blur.Enabled = true
script.Parent.Text = ("Blur - On")
end)

In regards to other questions, if this is in a localscript, it will only change the blur for the client.

the server camera is only visible on roblox studio in test mode it appears when you change from client to server side

That wouldn’t work either it will just error because there is no actual if statement.
@seancool07777 already provided a working code snippet.

1 Like

well your working code has an else but no if, how would that work?

Fixed it, sorry about that. 30char

@seancool07777’s script wouldn’t work more than once, as it’s checking if the text is Blur - On, but below, it is Blur = On.

You don’t need any if statements, this is the shortened (and more readable) code:

local Lighting = game:GetService("Lighting")
local blur = Lighting.Blur

local button = script.Parent

button.Activated:Connect(function()
    blur.Enabled = not blur.Enabled
    button.Text = "Blur - " .. (blur.Enabled and "Off" or "On")
end)

a = not a is a neat trick to “toggle” a boolean variable from true <-> false.

3 Likes

Thanks man! This helped a lot! Also, this is a local script. Will this only appear for yourself?