Object not detected by the script, although is there

Hi,

My intro depends on objects in the workplace, but although it worked when I fist set it up, it is giving me the following error now and I failed at identifying the problem:

Error: Cam1 is not a valid member of Model "Workspace.CameraPositions.Cam1

local player = game.Players.LocalPlayer
local tween = game:GetService("TweenService")
local cam = workspace.Camera
--local scenes = workspace.CameraPositions  
local scenes = workspace:WaitForChild("CameraPositions")
local currentTween = nil
local looping = true

local begincamera = function()
	looping = true
	script.Parent.Parent:WaitForChild("UIinterfaz").Enabled = false
	script.Parent.Enabled = true
	repeat wait() until cam.CameraSubject ~= nil
	cam.CameraType = Enum.CameraType.Scriptable

	while looping do

		for i, v in pairs(scenes:GetChildren()) do

			if looping == false then return end

			cam.CFrame = v["Cam1"].CFrame

			currentTween = tween:Create(cam, TweenInfo.new(10), {CFrame = v["Cam2"].CFrame})

			currentTween:Play()

			wait(10)
		end
	end
end

thank you for your help!

Space

1 Like

v is Cam1. You can do CameraPositions.Cam1. You’re looping through scenes (CameraPositions), so v is going to be either Cam1 or Cam2, but you obviously can’t do Cam["Cam1"]. The error is obvious, read it again - Cam1 is not valid a member of Cam1. To fix this, remove the for loop and replace v["Cam1"] with scenes.Cam1 and v["Cam2"] with scenes.Cam2.

I just noticed, you should probably remove v["Cam1"].CFrame, cause it literally contains no CFrame regarding the fact that it’s a model. Other than that, try to use v:FindFirstChild("Cam1") instead.