Help With Settings Script

Hello i know this is probably very easy but i tried what i knew and it didn’t work.

Here is my settings LocalScript inside a ScreenGui inside a Frame inside a TextButton
local h = false

script.Parent.Value.Value = true

script.Parent.MouseButton1Click:Connect(function()

if h == false then

script.Parent.Parent.Parent.Parent.MotionBlur.Disabled = true

game.Workspace.CurrentCamera.Blur:Destroy()

script.Parent.TextBox.Text = "Off"

script.Parent.Value.Value = false

script.Parent.TextBox.BackgroundColor3 = Color3.fromRGB(255, 0, 0)

h = true

else

script.Parent.Parent.Parent.Parent.MotionBlur.Disabled = false

script.Parent.TextBox.Text = "On"

script.Parent.Value.Value = true

script.Parent.TextBox.BackgroundColor3 = Color3.fromRGB(85, 255, 0)

h = false

end

end)

The Value is in the TextButton to make sure that when it is enabled the motion blur in the Camera
https://gyazo.com/e82aa5ca6623b6124c04720dce35937e
And The one in StarterGui
https://gyazo.com/a64fd49c35a52fc18eeeaef47c5ec9ee

They will disable… but that is the problem, i did this
if script.Parent.Value.Value == false then

script.Parent.Parent.Parent.Parent.Parent.MotionBlur.Disabled = true

game.Workspace.CurrentCamera.Blur.Enabled = false

end

To make sure that when the value is disabled that it will automatically delete the blur and disable the motion blur LocalScript, but i am sure i put the code in the right place and the bottom of the main code below the ends.

Gui Setup
https://gyazo.com/c3b4f09de8025b57933eef3a22112336

2 Likes

Your code is not very readable. I suggest adding indentations. Also you should Stop Using Gyazo.

1 Like
Okay, here's how you ~should~ have formatted (and written!!!) your code:
local textButton = script.Parent
local valueObject = textButton:WaitForChild("Value")
local motionBlur = textButton.Parent.Parent.Parent.MotionBlur

local h = false
valueObject.Value = true

textButton.MouseButton1Click:Connect(function()
	if h == false then
		motionBlur.Disabled = true
		game.Workspace.CurrentCamera.Blur:Destroy()
		textButton.TextBox.Text = "Off"
		valueObject.Value = false
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		h = true
	else
		motionBlur.Disabled = false
		textButton.TextBox.Text = "On"
		valueObject.Value = true
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
		h = false
	end
end)
... and the snippet that you're asking about.
if valueObject.Value == false then
	motionBlur.Disabled = true
	game.Workspace.CurrentCamera.Blur.Enabled = false
end

Much more readable.

Scripts are always run top to bottom, line by line. So the first 5 lines (in my modified version of your script) are run, and then we reach this part:

textButton.MouseButton1Click:Connect(function()
        --blablabla
end)

This code does run at that time, and only once, when the script reaches that line. But still, the stuff inside the (function() ... end) part is run every time the TextButton is clicked, because it connectes the clicked event of the TextButton to a function. Specifically, the function that has no name and is defined inside the parentheses ( ) .

You suggested putting the snippet below all the rest of the code

Which would look like this
local textButton = script.Parent
local valueObject = textButton:WaitForChild("Value")
local motionBlur = textButton.Parent.Parent.Parent.MotionBlur
local h = false

valueObject.Value = true

textButton.MouseButton1Click:Connect(function()
	if h == false then
		motionBlur.Disabled = true
		game.Workspace.CurrentCamera.Blur:Destroy()
		textButton.TextBox.Text = "Off"
		valueObject.Value = false
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		h = true
	else
		motionBlur.Disabled = false
		textButton.TextBox.Text = "On"
		valueObject.Value = true
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
		h = false
	end
end)

if valueObject.Value == false then
	motionBlur.Disabled = true
	game.Workspace.CurrentCamera.Blur.Enabled = false
end

The code runs the first 5 lines, then connects the clicked event to a function, then runs the last few lines, starting with

if valueObject.Value == false then
    --blablabla
end

So it checks if the valueObject is set to false, if that’s the case disables the motion blur… but it only does this once. You probably want this check to run every time the TextButton is clicked (because that’s how often the Value changes), so you’ll have to put it inside a function that gets connected to the clicked event of the TextButton. We already have such a function, the one that toggles the Value property of the valueObject and all the other things. Putting it at the bottom of that function makes it run every time after the h variable has been “toggled”.

... which would look like this
local textButton = script.Parent
local valueObject = textButton:WaitForChild("Value")
local motionBlur = textButton.Parent.Parent.Parent.MotionBlur
local h = false

valueObject.Value = true

textButton.MouseButton1Click:Connect(function()
	if h == false then
		motionBlur.Disabled = true
		game.Workspace.CurrentCamera.Blur:Destroy()
		textButton.TextBox.Text = "Off"
		valueObject.Value = false
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		h = true
	else
		motionBlur.Disabled = false
		textButton.TextBox.Text = "On"
		valueObject.Value = true
		textButton.TextBox.BackgroundColor3 = Color3.fromRGB(85, 255, 0)
		h = false
	end

	--I moved the if statement to here
	if valueObject.Value == false then
		motionBlur.Disabled = true
		game.Workspace.CurrentCamera.Blur.Enabled = false
	end
end)

--Before the if statement was here

You should pretty much be able to just copy/paste the code in the last section into your LocalScript, but I hope the (admittedly pretty long winded :stuck_out_tongue: ) explanation helped you better understand the whys of where the snippet should go.

If you have questions, let me know

1 Like

I used it but it still comes back when i die i forgot to say in the post that the blur comes back when you die even though the person has the setting turned off that is what i added the bool for.

After dying

Does the GUI have ResetOnSpawn to true? Change it to false. You should now see the option being “On” when you reset your character if it is on.

1 Like

I turned that setting off before i made this post so its not that its that the blur comes back in the camera from the blur script in startergui even when the player has the option off im trying to make it so if the player has the option off in the settings and you die the blur script gets disabled quick and the blur deleted from the camera