Booleans in table doesn't change

  1. What do you want to achieve?
    I want my local script to check if the part’s attribute “Light” is true then set the boolean “LightEnabled” in the table to true.

  2. What is the issue? Include screenshots / videos if possible!
    It prints “false” in the table, even if the attribute is already true.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked for solutions yet I found nothing.

More details:
I have two tables. The manager and the Info. The info is inside the manager. The info contains the booleans.

The code below is inside a Heartbeat.

for index, region in pairs(SanityRegions) do -- 'SanityRegions' is already a GetChildren().
		-- Region Manager
		for i, regionInfo in pairs(regionManager) do
			local LightEnabled = regionInfo.LightEnabled -- Boolean in the info table
			-- Check attribute
			if region:GetAttribute("Light") == true then
				LightEnabled = true
			else
				LightEnabled = false
			end
			--
		end
		--
	end

prints “false” in the table in the output. I have other booleans too in the table and also doesn’t change for some reason. :frowning:

regionInfo.LightEnabled just returns the value in the key LightEnabled which means you can’t save it to a variable to set LightEnabled again.

So LightEnabled is a variable true or false and setting it to something else does nothing because you are setting the variable to a different value but not the table key.

Instead of LightEnabled = true try regionInfo.LightEnabled = true

1 Like

Thank you so much, this worked! This saved me a week there. :slight_smile: