Have you ever seen a game where they change the player’s camera? Such as Kitchen Gun by @Inkthirsty. In this tutorial I’ll explain how you can change the player’s camera view.
To start off, put a local script in StarterPack:
Now let’s hop into the script, let’s define the CurrentCamera and the custom camera you want the player to have. If you want, it might also be helpful to define the player. Like this:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CurrentCamera = game.Workspace.CurrentCamera
local NewCam = game.Workspace.NewCam
We’ll end up messing with the current camera later in the script, but first let’s make sure the camera can be changed. Make a function named, changeMode()
and put this inside:
function changeMode()
repeat wait()
CurrentCamera.CameraType = Enum.CameraType.Scriptable
until CurrentCamera.CameraType == Enum.CameraType.Scriptable
end
This will allow us to change the camera, and it will be helpful later. Now that we finished that, everything else is extremely easy.
Below the changemode()
function, make a function named changecamera()
. This is the function we will use to change the player’s camera. In the function put:
function changeCamera()
CurrentCamera.CFrame = NewCam.CFrame
wait()
end
That will change the camera’s CFrame, to change the camera into the part that you wanted it to change to.
If you go ahead and run it, you can see that nothing happens, that’s because you never triggered the functions. At the very bottom of the script, put:
changeMode()
changeCamera()
In the end we should have this script:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CurrentCamera = game.Workspace.CurrentCamera
local NewCam = game.Workspace.NewCam
function changeMode()
repeat wait()
CurrentCamera.CameraType = Enum.CameraType.Scriptable
until CurrentCamera.CameraType == Enum.CameraType.Scriptable
end
function changeCamera()
CurrentCamera.CFrame = NewCam.CFrame
wait()
end
changeMode()
changeCamera()
If you go ahead and run it your camera will change to the new camera! You can use this for numerous amount of projects you might want to develop.
I hope this helps you in the future, and thank you for taking your time to read this. Have a good day!