ViewportFrame.Changed returning property "CameraCFrame" which does not exist?

  1. What do you want to achieve?

I need to be able to use the .Changed event of ViewportFrame without it returning non-existent properties.

  1. What is the issue?

I am using viewport frames with rotating cameras to display models in a UI I am working on.

ViewportFrame.Changed:Connect(function(Property)
	print(ViewportFrame[Property])
end)

And the .Changed event keeps returning a property of ViewportFrame called “CameraCFrame”

image
Which as shown in this error, apparently does not exist.

  1. What solutions have you tried so far?

I’ve tried using a simple if statement to dismiss any properties that don’t exist.

ViewportFrame.Changed:Connect(function(Property)
	if ViewportFrame[Property] then
		print(Property)
	end
end)

But it seems that any attempt to run ViewportFrame[Property] while Property = “CameraCFrame” will throw the same error shown above.

I was tempted to just call this a glitch on Roblox’s side, but I wanted to consult with scripting support just in case I’m getting something wrong here.

This seems like unexpected behaviour for sure. I suggest filing a bug report in #platform-feedback:engine-bugs.

In the meantime, you have a few options.

  1. You can use :GetPropertyChangedSignal(PROPERTY_NAME) to listen for specific property value changes.

  2. You can pcall your property check before using it. Note that this isn’t necessarily the most efficient method of doing this.

viewportFrame.Changed:Connect(function(property)
    local success = pcall(function()
        return viewportFrame[property]
    end)
    if success then
        print(property .. " is a valid property")
    else
        -- pcall errored, property is nil
    end
end

I’m on mobile sorry for bad formatting or any issues with the example there.

1 Like

Thanks for such a quick reply. I’ll go file a report as suggested.

a[b] still throws an exception because you cannot index for a non-existent property at all. You can make a function that determines if a property exists.


Also I think it was @Maximum_ADHD who said a couple years ago that the Instance.Changed event leaked some internal property names in an old post I cannot find anymore. It could just be a bug though too.

local function has_property(instance, property)
    local has_property, data = pcall(function()
        return instance[property]
    end)
    return has_property and not instance:FindFirstChild(property) and typeof(data) ~= "RBXScriptSignal" and typeof(data) ~= "function"
end