Attempt to index boolean value, how to solve?

When I do this:

if script.Parent.Locked.Value == true then

I get this error:

attempt to index field ‘Locked’ (a boolean value)

I’m sure I’ve been doing it this way forever now, so why can I not do this anymore?

7 Likes

The problem is you are trying to reference a boolean property “Locked” in parts. If it is a BoolValue, you may need to reference it with :FindFirstChild(“Locked”), or not use Value if you are referencing the property.

20 Likes

Huh, that doesn’t really make any sense to me so I’ll have to reread what :FindFirstChild does. I thought it just would find the first name of whatever.

3 Likes

FindFirstChild returns the first child of that name, or nil. When referencing it with as “Instance.Index”, it will reference the property (Locked) or a child instance.

5 Likes

As an alternative, you could also reference it like this:

if script.Parent["Locked"].Value == true then

Although FindFirstChild has the benefit of it not erroring if it’s nil.

2 Likes

Smart Questions

4 Likes