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 ) explanation helped you better understand the whys of where the snippet should go.
If you have questions, let me know