Toggle for camera perspective view

so like i have a camera for my menu. the camera tilts with where the mouse is, basically the camera is perfect. but what im looking for is a way to toggle this camera so the perspective can go back to the player’s character whenever i want. right now im just using renderstepped to repeat it forever and i actually dont know how to switch it. pls go easy on me im barely know anything in scripting

local cam = workspace.Camera
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local maxTilt = 30

game:GetService("RunService").RenderStepped:Connect(function()
	if false then
		cam.CFrame = CFrame.lookAt(game.Workspace.Head.Position,game.Workspace.Part.Position)
	else
		cam.CFrame = game.Workspace.Head.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),0)
	end
end)

thanks

Hello. If you tie an InputBegan connection to swap a boolean variable (“isCameraSwapped” here), you can check that in the RenderStepped connection to determine how the camera will work like so:

local isCameraSwapped = false

game:GetService('UserInputService').InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.R then -- doesn't have to be R
		isCameraSwapped = not isCameraSwapped -- if it's true, set it to false and if it's false, set it to true
	end
end)

game:GetService('RunService').RenderStepped:Connect(function()
	if isCameraSwapped then
		-- use camera type 1
	else
		-- use camera type 2
	end
end)
1 Like

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