How to change camera on ProximityPrompt

Hello! I am making a shop in my game in which I want to change camera positions. But I am not sure how. Right now my camera stays in a corner position. But I want it to face the PC if I press E? How would I do this?
Capture
Here is the code I am using right now.

Putting the camera in the corner:

local camera = workspace.Camera
local part = workspace.CameraPart

while true do
wait(.01)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end

The ProximityPrompt script:

local proximity = workspace.Prompts.PC.ProximityPart.ProximityPrompt -- Location of ProximityPrompt
local ProximityPromptService = game:GetService("ProximityPromptService")

proximity.Triggered:Connect(function()
	local GUI = script.Parent:WaitForChild("BobGUI") 
	GUI.Enabled = not GUI.Enabled
end)

local GUI = script.Parent:WaitForChild("BobGUI")

GUI.Frame.TextButton.Activated:Connect(function()
	GUI.Enabled = not GUI.Enabled
end)

Any info will help, Thanks!

1 Like

Alright, Firstly add a part near the PC it will determine the Player Camera when they Press E, Position it how you would like after that name it “PCCamera” and put it in workspace and drop this script.

local cam = game.Workspace.Camera
proximity.Triggered:Connect(function()
	local GUI = script.Parent:WaitForChild("BobGUI") 
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = game.Workspace.PCCamera.CFrame
	GUI.Enabled = not GUI.Enabled
end)
1 Like

You could also use TweenService to animate the Camera movement so it will tween to that Part.

local cam = game.Workspace.Camera
proximity.Triggered:Connect(function()
	local GUI = script.Parent:WaitForChild("BobGUI") 
cam.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(cam, TweenInfo.new(), {CFrame = game.Workspace.PCCamera.CFrame}:Play()
	GUI.Enabled = not GUI.Enabled
end)

Try using CFrame.lookAt like this:

-- This is the PC object you want the camera to look at
local pc

-- This is a part you can add in front of the pc where the camera will move to
local camPartForPC

-- This is the camera you want to move/rotate
local camera

-- This simply sets the camera to the camPartForPC position, looking at the PC
camera.CFrame = CFrame.lookAt(camPartForPC.Position, pc.Position)