Moving Camera to Another Part, Other than the Starting Part, Does not Work

Good Day

Here is my issue:
I’m trying to get the Player’s camera to change position from one part to another.
The first part is the part used for the game’s starting menu. The second is where I want to carry the camera to look at a specific area. I have a script that is located within Starter player scripts in a local script, which contains:

game:GetService("Players").PlayerAdded:Connect()

local MenuCam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local FocusPart = game.Workspace.GameSetCameraPositions.Menu.MenuFocusPart

MenuCam.CameraType = "Watch"
MenuCam.CameraSubject = FocusPart

while wait() do
	
	local Camera6 = game.Workspace.GameSetCameraPositions.SecurityCameras.Cam6
	local PlayButton = game.StarterGui.ScreenGui.PlayButton

	if
		PlayButton.Active ~= true	
	then
		MenuCam.CameraType = "Watch"
		MenuCam.CameraSubject = Camera6
	end
end

The first part of the code works perfectly. However, up until “while wait() do” is giving issues. I want to detect when the play button is hidden, to move it to the position of “Camera6”.

I know that I am probably supposed to use “Scriptable” as the camera type, however, when I do, the entire screen turns the colour of the menu frame. When the play button is clicked and the frame dissappears, the camera only shows grey.

Can someone help?

Also, if this is in the wrong channel or catergory, please let me know so that I may change that.

Thank you!

1 Like

the PlayButton is on StarterGui. you need to actually find the PlayerGui to detect his PlayButton

(Edit: remember that everything in the starterGui will duplicate into the LocalPlayer.PlayerGui.)
Also the first line code will give you an error because the Connect needs a value which has to be an function.

back to the code.

lets say that the LocalScript its inside the ScreenGui of the PlayButton.

local MenuCam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local FocusPart = game.Workspace.GameSetCameraPositions.Menu:WaitForChild("MenuFocusPart")

MenuCam.CameraType = "Watch"
MenuCam.CameraSubject = FocusPart


local Camera6 = game.Workspace.GameSetCameraPositions.SecurityCameras.Cam6
local PlayButton = script.Parent.PlayButton ---- you are using the actual player playbutton.

while wait() do

	if PlayButton.Active ~= true then
		
		MenuCam.CameraType = "Watch"
		MenuCam.CameraSubject = Camera6
		
	end
end

This should work if the LocalScript its inside your ScreenGui. hope this helps

2 Likes

Thank you for the explanations with the errors in my script, I have been trying to understand how to code for quite some time now. The script now works well.

Once again, thanks!

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