Changing camera on click

Hi!
I want to change my camera every time I click on an image button (something like Shindo Life)
here take a look:
StarterGui:
GUI
Workspace:
cams
and this is the cam script:

local cc = workspace.CurrentCamera

local Cam1 = workspace.MainCamera
local Cam2 = workspace.EditCharacterCamera
local Cam3 = workspace.ModeCam

local CamButton1 = script.Parent.UpButton
local CamButton2 = script.Parent.DownButton

local Button1 = script.Parent.PlayButton
local Button2 = script.Parent.EditCharacterButton
local Button3 = script.Parent.ModeButton

wait(.001)

cc.CameraType = Enum.CameraType.Scriptable

cc.CFrame = Cam1.CFrame


CamButton1.MouseButton1Click:Connect(function()
	if cc.CFrame == Cam1 then
		Button1.Visible = true
		Button2.Visible = true
		Button3.Visible = false
	elseif cc.CFrame == Cam2 then
		Button1.Visible = false
		Button2.Visible = false
		Button3.Visible = true
	elseif cc.CFrame == Cam3 then
		Button1.Visible = false
		Button2.Visible = false
		Button3.Visible = true
	end
end)
CamButton2.MouseButton1Click:Connect(function()
	if cc.CFrame == Cam1 then
		Button1.Visible = true
		Button2.Visible = true
		Button3.Visible = false
	elseif cc.CFrame == Cam2 then
		Button1.Visible = false
		Button2.Visible = false
		Button3.Visible = true
	elseif cc.CFrame == Cam3 then
		Button1.Visible = false
		Button2.Visible = false
		Button3.Visible = true
	end
end)

why don’t tp the cams

What is your problem?

im new in coding and i dont know how to do that I tried lerp but I didn’t understand I just need some help to complete my code

Here’s a script that you can use in Roblox Studio to switch between different cameras when clicking on buttons:

-- Get the current camera and different cameras you want to switch to
local currentCamera = workspace.CurrentCamera
local cam1 = workspace.MainCamera
local cam2 = workspace.EditCharacterCamera
local cam3 = workspace.ModeCam

-- Get the buttons you want to click
local button1 = script.Parent.PlayButton
local button2 = script.Parent.EditCharacterButton
local button3 = script.Parent.ModeButton

-- Get the buttons to switch between cameras
local buttonSwitch1 = script.Parent.UpButton
local buttonSwitch2 = script.Parent.DownButton

-- Set the initial camera type to scriptable
currentCamera.CameraType = Enum.CameraType.Scriptable

-- Function to switch between cameras and update button visibility
function switchCamera(newCamera)
    currentCamera.CFrame = newCamera.CFrame
    button1.Visible = (newCamera == cam1)
    button2.Visible = (newCamera == cam2)
    button3.Visible = (newCamera == cam3)
end

-- Event handlers for button clicks
buttonSwitch1.MouseButton1Click:Connect(function()
    switchCamera(cam1)
end)

buttonSwitch2.MouseButton1Click:Connect(function()
    switchCamera(cam2)
end)

In plain English, what this script does is set up a system to switch between different cameras when you click on buttons. The switchCamera function is in charge of changing the current view and adjusting button visibility accordingly. The event handlers for buttonSwitch1 and buttonSwitch2 call this function with the respective cameras, creating a smooth camera switching experience when you interact with the buttons.

Feel free to replace the camera and button variables with your actual camera and button objects. If you have any questions or need further clarification, feel free to ask!

ty for your help but it has some problems first it’s not changing the camera it just rotates it and the camera is not at the main cam at the start



and I can zoom and unzoom it and second, it just changes between two cameras I want the up and down buttons to change between all the cameras no matter how many times I click them or what camera they are at I need them to go to the last and next cam

2 Likes