Not a valid member error. Camera position scripting?

I’m trying to make a first sight welcome gui thing which the player’s camera is pointing to a part of the map. When the player clicks the Play button, the gui button and text label will fade out and the CurrentCamera will be changed to player’s position. The thing is, I’m getting this error and I don’t know why, can anyone help:

image

image

script:

local TweenService = game:GetService("TweenService")
local camera = game.Workspace.CurrentCamera
local playBtn = script.Parent.PlayButton
local startCamera = game.Workspace.camera
script.Parent.Enabled = true

wait(0.1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = startCamera.CFrame


function clicked()
	local player = game.Players.LocalPlayer
	for i, v in pairs(script.Parent:GetDescendants()) do
		if v:IsA("Frame") then
			TweenService:Create(v, TweenInfo.new(0.5), {BackgroundTransparency = 1}):Play()
		elseif v:IsA("TextLabel") then
			TweenService:Create(v, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
		elseif v:IsA("TextButton") then
			TweenService:Create(v, TweenInfo.new(0.5), {TextTransparency = 1}, {BackgroundTransparency = 1}):Play()
			
			wait(0.75)
			script.Parent.Enabled = false
			camera.CameraType = Enum.CameraType.Custom
			camera.CameraSubject = player.Character.Humanoid
			
		end
	end
end

script.Parent.PlayButton.MouseButton1Click:Connect(clicked)

Members of workspace usually won’t be loaded the moment local scripts (especially if StreamingEnabled is on) so use :WaitForChild while indexing them

2 Likes

Yep, that fixed it, thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.