Error when i tried to use switch statements via tables

code sample:

local brightness = workspace.Settings.BrightnessValue
local loaded = workspace.Technical.LoadedValue
local gui
local BrightnessCases = {
	[1] = function()
		game.Lighting.ExposureCompensation = -1.69
	end,
	[2] = function()
		game.Lighting.ExposureCompensation = -1.42
	end,
	[3] = function()
		game.Lighting.ExposureCompensation = -1.20
	end,
}
--loading
loaded:GetPropertyChangedSignal("Value"):Connect(function()
	if loaded.Value == true then
		BrightnessCases[brightness.Value]
	end
end)

specifically BrightnessCases[brightness.Value]

local brightness = workspace.Settings.BrightnessValue
local loaded = workspace.Technical.LoadedValue
local gui

local BrightnessCases = {
	[1] = function()
		game.Lighting.ExposureCompensation = -1.69
	end,
	[2] = function()
		game.Lighting.ExposureCompensation = -1.42
	end,
	[3] = function()
		game.Lighting.ExposureCompensation = -1.20
	end,
}

loaded:GetPropertyChangedSignal("Value"):Connect(function()
	if loaded.Value == true then
		BrightnessCases[brightness.Value]()
	end
end)

Try his ?

You’re just indexing the function; you’re not calling it.

BrightnessCases[brightness.Value]() -- Calls the function

Alternatively, if you’re not going to add any further functionality, I recommend doing this:

local brightness = workspace.Settings.BrightnessValue
local loaded = workspace.Technical.LoadedValue
local gui
local BrightnessCases = {
	-1.69,
	-1.42,
	-1.20
}
--loading
loaded:GetPropertyChangedSignal("Value"):Connect(function()
	if loaded.Value == true then
		game.Lighting.ExposureCompensation = BrightnessCases[brightness.Value]
	end
end)

makes sense i guess. nice. roblos stop

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.