I'm working on a game in which the player will be able to play a variety of different arcade games. I want to make the camera move for this, which I've successfully done. However, I'm having issues with one game where I want to move the camera above the game and also have it look down at a specific part. When I attempt to do this, the player will either trip and have a stroke on the ground or be caught in a permanent kill loop.
Start of Game Code:
local CameraChange = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCamera")
Cabinet.Body.ClickDetector.MouseClick:Connect(function(player)
if not pause and player.leaderstats.Cash.Value >= price then
pause = true
CameraChange:FireClient(player, Cabinet.Name)
player.Character:MoveTo(TeleportSpot)
gameHandle(player)
CameraChange:FireClient(player, "Default")
pause = false
end
end)
Start of Camera Code:
local ChangeCamera = game:GetService("ReplicatedStorage"):WaitForChild("ChangeCamera")
local player = game:GetService("Players").LocalPlayer
local cameraCFrame = workspace.CurrentCamera.CFrame
local cameraSubject = workspace.CurrentCamera.CameraSubject
local cameraType = workspace.CurrentCamera.CameraType
local minZoom = player.CameraMinZoomDistance
local maxZoom = player.CameraMaxZoomDistance
ChangeCamera.OnClientEvent:Connect(function(changeTo)
if changeTo == "Default" then
workspace.CurrentCamera.CameraSubject = game:GetService("Players").LocalPlayer.Character.Humanoid
workspace.CurrentCamera.CFrame = cameraCFrame
workspace.CurrentCamera.CameraType = cameraType
player.CameraMinZoomDistance = minZoom
player.CameraMaxZoomDistance = maxZoom
else
local currentGame = workspace:FindFirstChild(changeTo)
if changeTo == "ClimbGame1" then
local subject = currentGame.Game.Walls.Back
workspace.CurrentCamera.CameraSubject = subject
workspace.CurrentCamera.Focus = subject.CFrame
workspace.CurrentCamera.CFrame = CFrame.new(Vector3.new(subject.Position.X,
subject.Position.Y, subject.Position.Z + 50))
workspace.CurrentCamera.CameraType = "Scriptable"
player.CameraMinZoomDistance = 50
player.CameraMaxZoomDistance = 50
elseif changeTo == "TileGame1" then
local subject = currentGame.Game.CameraSubject
workspace.CurrentCamera.CameraSubject = subject
workspace.CurrentCamera.Focus = subject.CFrame
workspace.CurrentCamera.CFrame = CFrame.new(Vector3.new(subject.Position.X,
subject.Position.Y + 50, subject.Position.Z), subject.Position)
workspace.CurrentCamera.CameraType = "Scriptable"
player.CameraMinZoomDistance = 50
player.CameraMaxZoomDistance = 50
Specifically, I'm having issues with this particular line of code:
workspace.CurrentCamera.CFrame = CFrame.new(Vector3.new(subject.Position.X,
subject.Position.Y + 50, subject.Position.Z), subject.Position)
From what I've observed, it would appear changing the Camera's CFrame using CFrame.new(position, lookat) is causing this issue. Is there a way to fix this?

2 comments
Try switching camera type to "Scriptable" before changing its CFrame. I've had issues in the past with the camera doing weird things otherwise.
The player is still being killed with this change.