I’ve tried using Enum.CameraType.Fixed, but it locks the camera and doesn’t let it move.
How may I achieve this? Also everytime when I switch from Enum.CameraType.Scriptable to another then switch it back, the camera does not move and stays in the same place.
It works but it is in a weird angle. Which integer should i change to make it look down from above? Also, I got this:
attempt to index nil with 'HumanoidRootPart'
I used HumeanoidRootPart instead of Head because the head is too shaky but the HumanoidRootPart is smoother. Did I do something wrong?
Script
local camera = workspace.CurrentCamera
local character = game.Players.LocalPlayer.Character
workspace.House.Door.ClickDetector.MouseClick:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
while wait() do
camera.CFrame = CFrame.new(character.HumanoidRootPart.Position + Vector3.new(3,2,4), character.HumanoidRootPart.Position)
end
end)
Never use while wait() do; it’s poor practice, especially in this case because it doesn’t loop nearly fast enough to make the camera smooth. Instead, use RunService as explained in this DevHub article.
To put it simply, this error means that you haven’t actually found the player’s character. This may be either because your script runs on the server or because the player’s character hasn’t loaded yet when you were initialising the character variable. If this is a local script, you could simply use this:
local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
That line is explained in the first post that I linked.
I am using a local script, and the character must be loaded because it’s not activated when the game starts. I walk up to the door and press it, then this local script changes the camera angle and a server script teleports me into the house. I also changed while wait() do to RunService but it still doesn’t work.
Unless the script is initially disabled when the player joins the game, the character variable will instantly try to get the player’s character. The variable won’t update itself from nil later on if the character wasn’t already loaded before the script was.
To fix the camera angle, just switch around the numbers in the Vector3.new part. The first one moves the camera sideways, the second one moves the camera up or down and the last one makes it go forwards or backwards.