Change camera positions on key press

  1. What do you want to achieve?
    Multiple camera blocks, can press Q or E to cycle through the different camera angles. Camera angles are all fixed positions. Currently only have one camera angle.
  2. What is the issue? Include screenshots / videos if possible!
    No idea if I should tackle this - not very good at scripting, I’m more a builder!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Just had a little google around, had a look at some YouTube videos, had no luck.
local character = player.Character
local camera = workspace.CurrentCamera

repeat wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

camera.CFrame = workspace.CameraPos.CFrame
1 Like

local cameraNum = 1;
local maxCamera = 5;
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(key,state)
	if not state then
		if key.KeyCode == Enum.KeyCode.E then
			cameraNum = cameraNum + 1;
			if cameraNum == maxCamera then
				cameraNum = 1;
			end;
		end;
		
		
		if key.KeyCode == Enum.KeyCode.Q  then
			cameraNum = cameraNum - 1;
			wait();
			if cameraNum == 0 then
				cameraNum = 1;
			end;
		end;
		
		if cameraNum == 2 then
			workspace.CurrentCamera.CFrame = workspace.Camera2.CFrame
			workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable;
		elseif cameraNum == 3 then
			-- and so on with the code
		end;
	end;
end)
1 Like

I hope this will help with what you’re trying to do. I don’t really understand fully from your displayed code, sorry if this is no help.

1 Like

This should work, if it doesn’t then say so I believe I could show you how you could do it. (GJ bmx on the code!)

1 Like

Update:
I press E and it goes to a camera. Pressing anything else does nothing.

Note, I have 2 cameras currently. Camera1 & Camera2

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local cameraPos = workspace:WaitForChild("CameraPos")
local uis = game:GetService("UserInputService")

repeat task.wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable

uis.InputBegan:Connect(function(key, processed)
	if processed then
		return
	end
	
	if key.KeyCode == Enum.KeyCode.Q then
		camera.CFrame = cameraPos.CFrame
	end
end)

uis.InputBegan:Connect(function(key, processed)
	if processed then
		return
	end
	
	if key.KeyCode == Enum.KeyCode.E then
		camera.CFrame = hrp.CFrame * CFrame.new(0, 20, 0)
	end
end)

Triggered when the “Q” key is pressed. The “E” key focuses the camera on the player’s character model.

3 Likes