I have an issue with the Camera currently in the part moving to another part

Hello guys, I have issues when I really wanted to make a GUI button when the player enters the game, their player camera will move to the part camera for the menu, and when the player clicks a GUI button, it will move the player camera from the camera CFrame part to another CFrame part without end time.

Here is the script that I wrote in order for the player to join, the player camera would move to the Part1 CFrame of the camera, if a player clicks the GUI button, the camera would move to Part2 CFrame of the camera, I don’t know what caused it If you guys can correct my code for it to work, maybe my script isn’t working and thus, this is in a LocalScript in a GUI.

Explorer:
image

LocalScript:

local player = game.Players.LocalPlayer
local character = player.CharacterAdded
local Mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera

local defaultCframe = camera.CFrame
local view = 50

local debouncesingleplayer = false

function updateCamera()
	camera.FieldOfView = 50
	camera.CFrame = game.Workspace.Part1.CFrame
end

function updateCamera2()
	camera.FieldOfView = 50
	camera.CFrame = game.Workspace.Part2.CFrame
end

game:GetService("RunService").RenderStepped:Connect(updateCamera) -- this one is where the player joined, the player current camera would move to the part CFrame camera.

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
	print("clicked test")
	camera.CameraType = Enum.CameraType.Custom
	camera.FieldOfView = 70
	camera.CFrame = game.Workspace.Part2.CFrame -- this is a part where I wanted to move the part1 cframe camera to the part2 cframe camera
	--script.Parent.Frame:Destroy() -- this is a part where the player part camera moves back to the player
	--script:Destroy()
end)

It would be appreciated if you guys can correct my scripting error.

I see your issue. You still have the RenderStepped event running, so it is infinitely updating the camera CFrame to the Part1 CFrame. You need to set the CameraType to Scriptable, and get rid of the RenderStepped event. You should not need to have a loop that always changes the CFrame of the camera when it’s on Scriptable. Let me know if that works.

it doesn’t solve anything, I tried removing the “renderstepped” part and it doesn’t attach the camera to the part when the player joins without the “renderstepped” :frowning: so any alternatives?

local player = game.Players.LocalPlayer
local character = player.CharacterAdded
local Mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera

local defaultCframe = camera.CFrame
local view = 50

local debouncesingleplayer = false

function updateCamera()
    camera.CameraType = Enum.CameraType.Scriptable
	camera.FieldOfView = 50
	camera.CFrame = game.Workspace.Part1.CFrame
end

function updateCamera2()
    camera.CameraType = Enum.CameraType.Scriptable
	camera.FieldOfView = 50
	camera.CFrame = game.Workspace.Part2.CFrame
end

updateCamera()

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
	print("clicked test")
	updateCamera2()
	--script.Parent.Frame:Destroy() -- this is a part where the player part camera moves back to the player
	--script:Destroy()
end)

the script does not locked on to the part1 camera when the player joins, it starts with the normal player camera, not the part camera, and i will try to provide the file here: camera test.rbxl (35.4 KB) with your scripts in it