What on earth is this error?

I got this error with a script that toggles lights automatically at day/night at a building. (currently tidying it, but can’t even get it working)

I literally have no clue what this means, nor can I find anything about it.

Script with error in it:

local parlour = script.Parent.Parent.Parent.Parent
local nightValue = game.Workspace.DayNightCycleValues.IsNight

function runForLoop()
		parlour = nil
	parlour = script.Parent.Parent.Parent.Parent
for i, v in pairs(parlour:GetDescendants()) do
	if v:IsA("SurfaceLight") and v.Name == "NightOnly" then
		if nightValue.Value == true then
			v.Enabled = true
		end
		if nightValue.Value == false then
			v.Enabled = false
		end
	end
end
end

nightValue:GetPropertyChangedSignal("Value"):connect(runForLoop)
parlour.ChildAdded:connect(runForLoop)

Help clarifying what this error is would be very useful.

Cheers, reddust1

This error appears because you tried to read / write from / onto an object that is locked behind other permissions / higher security level. You may have tried to call GetDescendants on game which in turn returned locked classes / instances.

You can pcall your function inside the for loop, or you can change the parent at which you called GetDescendants on.

(for other scripters reading this, correct me if any of my “facts” are wrong)

2 Likes

You know funnily enough, this was actually a mistake in the hierarchy in explorer, I hadn’t noticed and rushed to make a post as I’ve never seen this error before. My bad, sorry for wasting your time.

Thanks for replying and helping though, I do appreciate it.

Marked your post as solution incase anyone else needs this

1 Like