Changing Lighting properties with ModuleScript

Hello! I’m doing a Script that changes the Lighting properties with a ModuleScript.
There’s no error and the Lighting won’t change, even the print included don’t display on the Output.

Here is the Module Script + the script
Module Script

local Data = {
	["Lighting"] = {
		["ClockTime"] = -9.5866670608521,
		["ColorShift_Bottom"] = Color3.fromRGB(0, 0, 0),
		["FogColor"] = Color3.fromRGB(192, 192, 192),
		["FogEnd"] = 100000,
		["FogStart"] = 0,
		["EnvironmentDiffuseScale"] = 0,
		["EnvironmentSpecularScale"] = 0,
		["ExposureCompensation"] = 0,
		["GeographicLatitude"] = 44.602531433105,
		["Ambient"] = Color3.fromRGB(152, 152, 152),
		["OutdoorAmbient"] = Color3.fromRGB(128, 128, 128),
		["ShadowSoftness"] = 0.20000000298023,
		["Brightness"] = 2,
		["ColorShift_Top"] = Color3.fromRGB(0, 0, 0),
		["GlobalShadows"] = true
	},
}

Script

		local Save = require(Module)
		
		local Lighting = game:GetService("Lighting")
		Lighting:ClearAllChildren()
		
		for v, Setting in ipairs(Save.Lighting) do
			print("Changing")
			print(v, Setting)
			Lighting[v] = Setting
		end

I don’t have an idea why it don’t work so i hope you guys can help me!

I somehow fixed it by changing in ipairs by in pairs.

1 Like

For an explanation, ipairs is used for array iteration:

local array = {"value", "another value", 3} -- this is what an array could look like

while pairs is used for dictionaries:

local dictionary = { -- this is what a dictionary can look like
    index = value,
    ['another_index'] = "another value"
}

In your case, your table is a dictionary which is why pairs worked.

2 Likes