Attempt to index nil with 'Name'

RE.ChangeLighting.OnClientEvent:Connect(function()
	for i, v in pairs(workspace.WSStopStorage:GetChildren()) do
		if v:IsA("Model") then
			local model = workspace.WSStopStorage:GetChildren()
			local StopValues = model.Values
			print(StopValues.Name) -- attempt to index nil with 'Name'
			LightModule.TweenLighting(
				2, -- Speed
				StopValues.Ambience.Value,
				StopValues.Blur.Value,
				StopValues.CCBrightness.Value,
				StopValues.CCContrast.Value,
				StopValues.CCSaturation.Value,
				StopValues.CCTintColor.Value,
				StopValues.ClockTime.Value,
				StopValues.EnvironmentDiffuseScale.Value,
				StopValues.EnvironmentSpecularScale.Value,
				StopValues.FogColor.Value,
				StopValues.FogEnd.Value,
				StopValues.FogStart.Value,
				StopValues.OutdoorAmbience.Value
			)
		end
	end
end)

StopValues comes out as nil, is there another way to localize something through a for loop?

(the objects get destroyed and cloned, so I can’t put a preset name, if that makes sense)

Any help is apprciated!

It looks like the issue might be that you are trying to access a property of a nil object. The StopValues object is coming out as nil when you try to print its Name property. This likely means that one of the model.Values properties you are trying to access is nil. To localize something through a for loop, you could check to make sure each property you access is not nil before accessing its subproperties.

if model and model.Values and StopValues then
    print(StopValues.Name)
    -- Your other code here
end
1 Like

Yes that worked, thank you!!

(i think it was maybe just loading too fast)

Of course. I’ll be glad to help anytime

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