Toggle switch do not working

I scripted a toggle switch with lighting or post-processing that looks changes, but it malfunctions when it is used as a tween position. Can you see my script? Just look at it:

local p = script.Parent

local p2 = p.Parent.CategoryFrame

local backButton = p.Parent:WaitForChild("BackButton")

local prop1 = p:WaitForChild("Property1")
local prop2 = p:WaitForChild("Property2")
local prop3 = p:WaitForChild("Property3")
local prop4 = p:WaitForChild("Property4")
local prop5 = p:WaitForChild("Property5")
local prop6 = p:WaitForChild("Property6")
local prop7 = p:WaitForChild("Property7")
local prop8 = p:WaitForChild("Property8")
local prop9 = p:WaitForChild("Property9")
local prop10 = p:WaitForChild("Property10")
local prop11 = p:WaitForChild("Property11")
local prop12 = p:WaitForChild("Property12")
local prop13 = p:WaitForChild("Property13")
local prop14 = p:WaitForChild("Property14")
local prop15 = p:WaitForChild("Property15")
local prop16 = p:WaitForChild("Property16")
local prop17 = p:WaitForChild("Property17")
local prop18 = p:WaitForChild("Property18")
local prop19 = p:WaitForChild("Property19")
local prop20 = p:WaitForChild("Property20")
local prop21 = p:WaitForChild("Property21")
local prop22 = p:WaitForChild("Property22")
local prop23 = p:WaitForChild("Property23")
local prop24 = p:WaitForChild("Property24")
local prop25 = p:WaitForChild("Property25")
local prop26 = p:WaitForChild("Property26")
local prop27 = p:WaitForChild("Property27")
local prop28 = p:WaitForChild("Property28")
local prop29 = p:WaitForChild("Property29")
local prop30 = p:WaitForChild("Property30")
local prop31 = p:WaitForChild("Property31")
local prop32 = p:WaitForChild("Property32")
local prop33 = p:WaitForChild("Property33")

local envProp1 = p:WaitForChild("EnvProperty1")
local envProp2 = p:WaitForChild("EnvProperty2")
local envProp3 = p:WaitForChild("EnvProperty3")
local envProp4 = p:WaitForChild("EnvProperty4")
local envProp5 = p:WaitForChild("EnvProperty5")
local envProp6 = p:WaitForChild("EnvProperty6")
local envProp7 = p:WaitForChild("EnvProperty7")
local envProp8 = p:WaitForChild("EnvProperty8")
local envProp9 = p:WaitForChild("EnvProperty9")

local value1 = prop1:WaitForChild("Value")
local value2 = prop2:WaitForChild("Value")
local value3 = prop4:WaitForChild("Value")
local value4 = prop5:WaitForChild("Value")
local value5 = prop6:WaitForChild("Value")
local value6 = prop7:WaitForChild("Value")
local value7 = prop8:WaitForChild("Value")
local value8 = prop9:WaitForChild("Value")
local value9 = prop10:WaitForChild("Value")
local value10 = prop11:WaitForChild("Value")
local value11 = prop12:WaitForChild("Value")
local value12 = prop13:WaitForChild("Value")
local value13 = prop14:WaitForChild("Value")
local value14 = prop16:WaitForChild("Value")
local value15 = prop17:WaitForChild("Value")
local value16 = prop18:WaitForChild("Value")
local value17 = prop20:WaitForChild("Value")
local value18 = prop21:WaitForChild("Value")
local value19 = prop22:WaitForChild("Value")
local value20 = prop24:WaitForChild("Value")
local value21 = prop25:WaitForChild("Color")
local value22 = prop27:WaitForChild("Value")
local value23 = prop28:WaitForChild("Value")
local value24 = prop29:WaitForChild("Value")
local value25 = prop30:WaitForChild("Value")
local value26 = prop32:WaitForChild("Value")
local value27 = prop33:WaitForChild("Value")

local envValue1 = envProp1:WaitForChild("Color")
local envValue2 = envProp2:WaitForChild("Value")
local envValue3 = envProp3:WaitForChild("Color")
local envValue4 = envProp4:WaitForChild("Color")
local envValue5 = envProp5:WaitForChild("Value")
local envValue6 = envProp6:WaitForChild("Value")
local envValue7 = envProp8:WaitForChild("Color")
local envValue8 = envProp9:WaitForChild("Value")

local toggle1 = prop3:WaitForChild("Toggle")
local toggle2 = prop15:WaitForChild("Toggle")
local toggle3 = prop19:WaitForChild("Toggle")
local toggle4 = prop23:WaitForChild("Toggle")
local toggle5 = prop26:WaitForChild("Toggle")
local toggle6 = prop31:WaitForChild("Toggle")

local envToggle1 = envProp7:WaitForChild("Toggle")

local ligthing = game:WaitForChild("Lighting")
local atmos = ligthing:WaitForChild("Atmosphere")
local sky = ligthing:WaitForChild("Sky")
local bloom = ligthing:WaitForChild("Bloom")
local blur = ligthing:WaitForChild("Blur")
local colorCorrection = ligthing:WaitForChild("ColorCorrection")
local depthOfField = ligthing:WaitForChild("DepthOfField")
local sunRays = ligthing:WaitForChild("SunRays")

value1.Text = atmos.Density
value2.Text = atmos.Offset
value3.Text = sky.MoonAngularSize
value4.Text = sky.MoonTextureId
value5.Text = sky.SkyboxBk
value6.Text = sky.SkyboxDn
value7.Text = sky.SkyboxFt
value8.Text = sky.SkyboxLf
value9.Text = sky.SkyboxRt
value10.Text = sky.SkyboxUp
value11.Text = sky.StarCount
value12.Text = sky.SunAngularSize
value13.Text = sky.SunTextureId
value14.Text = bloom.Intensity
value15.Text = bloom.Size
value16.Text = bloom.Threshold
value17.Text = blur.Size
value18.Text = colorCorrection.Brightness
value19.Text = colorCorrection.Contrast
value20.Text = colorCorrection.Saturation
value21.BackgroundColor3 = colorCorrection.TintColor
value22.Text = depthOfField.FarIntensity
value23.Text = depthOfField.FocusDistance
value24.Text = depthOfField.InFocusRadius
value25.Text = depthOfField.NearIntensity
value26.Text = sunRays.Intensity
value27.Text = sunRays.Spread

envValue1.BackgroundColor3 = ligthing.Ambient
envValue2.Text = ligthing.Brightness
envValue3.BackgroundColor3 = ligthing.ColorShift_Top
envValue4.BackgroundColor3 = ligthing.ColorShift_Bottom
envValue5.Text = ligthing.EnvironmentDiffuseScale
envValue6.Text = ligthing.EnvironmentSpecularScale
envValue7.BackgroundColor3 = ligthing.OutdoorAmbient
envValue8.Text = ligthing.ShadowSoftness

backButton.Activated:Connect(function()
	p.Visible = false
	p2.Visible = true
	backButton.Visible = false
end)

value1.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		atmos.Density = value1.Text
	end
end)

value2.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		atmos.Offset = value2.Text
	end
end)

toggle1.Knob.Activated:Connect(function()
	if sky.CelestialBodiesShown == false then
		toggle1.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle1.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		sky.CelestialBodiesShown = true
	else
		toggle1.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle1.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		sky.CelestialBodiesShown = false
	end
end)

value3.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.MoonAngularSize = value3.Text
	end
end)

value4.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.MoonTextureId = value4.Text
	end
end)

value5.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxBk = value5.Text
	end
end)

value6.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxDn = value6.Text
	end
end)

value7.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxFt = value7.Text
	end
end)

value8.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxLf = value8.Text
	end
end)

value9.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxRt = value9.Text
	end
end)

value10.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SkyboxUp = value10.Text
	end
end)

value11.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.StarCount = value11.Text
	end
end)

value12.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SunAngularSize = value12.Text
	end
end)

value13.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sky.SunTextureId = value13.Text
	end
end)

toggle2.Knob.Activated:Connect(function()
	if bloom.Enabled == false then
		toggle2.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle2.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		bloom.Enabled = true
	else
		toggle2.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle2.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		bloom.Enabled = false
	end
end)

value14.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		bloom.Intensity = value14.Text
	end
end)

value15.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		bloom.Size = value15.Text
	end
end)

value16.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		bloom.Threshold = value16.Text
	end
end)

toggle3.Knob.Activated:Connect(function()
	if blur.Enabled == false then
		toggle3.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle3.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		blur.Enabled = true
	else
		toggle3.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle3.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		blur.Enabled = false
	end
end)

value17.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		blur.Size = value17.Text
	end
end)

value18.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		colorCorrection.Brightness = value18.Text
	end
end)

value19.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		colorCorrection.Contrast = value19.Text
	end
end)

toggle4.Knob.Activated:Connect(function()
	if colorCorrection.Enabled == false then
		toggle4.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle4.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		colorCorrection.Enabled = true
	else
		toggle4.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle4.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		colorCorrection.Enabled = false
	end
end)

value20.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		colorCorrection.Saturation = value20.Text
	end
end)

toggle5.Knob.Activated:Connect(function()
	if depthOfField.Enabled == false then
		toggle5.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle5.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		depthOfField.Enabled = true
	else
		toggle5.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle5.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		depthOfField.Enabled = false
	end
end)

value22.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		depthOfField.FarIntensity = value22.Text
	end
end)

value23.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		depthOfField.FocusDistance = value23.Text
	end
end)

value24.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		depthOfField.InFocusRadius = value24.Text
	end
end)

value25.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		depthOfField.NearIntensity = value25.Text
	end
end)

toggle6.Knob.Activated:Connect(function()
	if sunRays.Enabled == false then
		toggle6.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle6.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		sunRays.Enabled = true
	else
		toggle6.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle6.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		sunRays.Enabled = false
	end
end)

value26.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sunRays.Intensity = value26.Text
	end
end)

value27.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		sunRays.Spread = value27.Text
	end
end)

envValue2.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		ligthing.Brightness = envValue2.Text
	end
end)

envValue5.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		ligthing.EnvironmentDiffuseScale = envValue5.Text
	end
end)

envValue6.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		ligthing.EnvironmentSpecularScale = envValue6.Text
	end
end)

envToggle1.Knob.Activated:Connect(function()
	if ligthing.GlobalShadows == false then
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		ligthing.GlobalShadows = true
	else
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		ligthing.GlobalShadows = false
	end
end)

envValue8.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		ligthing.ShadowSoftness = envValue8.Text
	end
end)

I am just so hard to work as it can, but how do I fix the only toggle switch that can work?

1 Like

In Which line of the script is the error?

There’s an error of the lines:

toggle1.Knob.Activated:Connect(function()
	if sky.CelestialBodiesShown == false then
		toggle1.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle1.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		sky.CelestialBodiesShown = true
	else
		toggle1.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle1.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		sky.CelestialBodiesShown = false
	end
end)

toggle2.Knob.Activated:Connect(function()
	if bloom.Enabled == false then
		toggle2.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle2.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		bloom.Enabled = true
	else
		toggle2.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle2.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		bloom.Enabled = false
	end
end)

toggle3.Knob.Activated:Connect(function()
	if blur.Enabled == false then
		toggle3.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle3.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		blur.Enabled = true
	else
		toggle3.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle3.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		blur.Enabled = false
	end
end)

toggle4.Knob.Activated:Connect(function()
	if colorCorrection.Enabled == false then
		toggle4.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle4.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		colorCorrection.Enabled = true
	else
		toggle4.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle4.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		colorCorrection.Enabled = false
	end
end)

toggle5.Knob.Activated:Connect(function()
	if depthOfField.Enabled == false then
		toggle5.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle5.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		depthOfField.Enabled = true
	else
		toggle5.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle5.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		depthOfField.Enabled = false
	end
end)

toggle6.Knob.Activated:Connect(function()
	if sunRays.Enabled == false then
		toggle6.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle6.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		sunRays.Enabled = true
	else
		toggle6.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		toggle6.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		sunRays.Enabled = false
	end
end)

envToggle1.Knob.Activated:Connect(function()
	if ligthing.GlobalShadows == false then
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		ligthing.GlobalShadows = true
	else
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		ligthing.GlobalShadows = false
	end
end)

cloudsToggle1.Knob.Activated:Connect(function()
	if clouds.Enabled == false then
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.05, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.254902, 0.870588, 0.305882)
		clouds.Enabled = true
	else
		envToggle1.Knob:TweenPosition(
			UDim2.new(0.57, 0, 0.06, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.5
		)
		wait(0.51)
		envToggle1.Knob.BackgroundColor3 = Color3.new(0.870588, 0.254902, 0.266667)
		clouds.Enabled = false
	end
end)

It is a way to should have to fix it.

I mean, which number of line on the code.

1 Like