"Part is not a valid member of BillboardGui" even though it isn't even supposed to be a member of it

Alright so I have this script that is supposed to loop through a folder and if it finds a descendant that has a specific names it gives it pathways to global parts (ViewPart, Icon, etc) and ViewPart is causing problems here. The error says it isn’t a valid member of BillboardGui even though it is in a model.


Here is the code:

for i, v in pairs(WorkingMonitors:GetDescendants()) do
	
	if v.Name == "MonitorOrder" then
		
		local PlayerViewPart = v.Parent.ViewPart
		local Icon = v.Parent.ExampleMonitor.MonitorProxTemplate

And here is the hierarchy
image

where is my mistake??

2 Likes

There could be something named similarly inside the MonitorProxTemplate BillboardGui since you are looping through every descendant of the folder, making it pass the name check and try to access ViewPart (which doesn’t exist there, giving the error)

2 Likes

The only thing inside the MonitorProxTemplate is a button.

1 Like

Remove “.MonitorProxTemplate”

characterAdder

2 Likes

You may be referring to BillboardGui instead of Monitor1 in your variable. You can also try making it so this script loops through each individual Monitor (Monitor1, Monitor 2, e.g.)

2 Likes

Looking at your code and the “hierachy”(???)

I can safely say that it is because of the fact that you’re basically looking for a non-existent instance.

Here is the code:

for i, monitor in pairs(WorkingMonitors:GetDescendants()) do
	local MonitorName = tostring("Monitor" .. i)
       
        if monitor.Name == MonitorName then
              for i, v in pairs(monitor:GetDescendants()) do
                if v.Name == "MonitorOrder" then
		
		        local PlayerViewPart = monitor.ViewPart
		        local Icon = monitor.ExampleMonitor.MonitorProxTemplate
               end
            end
        end

Let me know if I have made a mistake since I’ve written a code without using studio to check if it’s correct.

2 Likes

Hello!

It is looking like your trying to access ViewPart, but it is a child of ExampleMonitor.

Try indexing it by doing this:

local ViewPart = v.Parent.ExampleMonitor.ViewPart

If this does not work, try using WaitForChild on it.

Hopes this helps!

2 Likes