Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why am I getting this error when loading a map? [Attempt to index field]

Whenever I load the game, the map won't load because of this error? I have no idea why, Can someone help me?

Here is the script,

	local function set_lighting(mname)
		local dolist={"Ambient","ColorShift_Bottom","ColorShift_Top","OutdoorAmbient"}
		for i=1, #dolist do
			light[dolist[i]]=color(lightset[mname][dolist[i]][1]/255,lightset[mname][dolist[i]][2]/255,lightset[mname][dolist[i]][3]/255)
		end
		mapname.Value=lightset[mname].Name
	end

Here is the error that occurs when I load the game.

  20:53:34.461 - ServerScriptService.server:2152: attempt to index field '?' (a nil value)

Any help?

2 comments

0

The 4th line is cut off a bit, It says this. light[dolist[i]]=color(lightset[mname][dolist[i]][1]/255,lightset[mname][dolist[i]][2]/255,lightset[mname][dolist[i]][3]/255).

0

this code looks oddly familiar...

1 answer

local function set_lighting(mname)
    local dolist={"Ambient","ColorShift_Bottom","ColorShift_Top","OutdoorAmbient"}
    for i,v in pairs(dolist) do -- Switched to pairs to make it easier for you
        light[v]=Color3.new(lightset[mname][v][1]/255,lightset[mname][v][2]/255,lightset[mname][v][3]/255) -- You did not use "Color3.new" which is required for Color3 colors.
    end
    mapname.Value=lightset[mname].Name
end

If this helped, make sure to upvote/accept it!

1 comment

0

color was probably defined to be Color3.new

This discussion is preserved as it was. New answers, comments, and votes are closed.