The camera doesn't change its CFrame to a part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want for the players camera to be the view of a certain part, the same script worked before but since i have added some models and parts it stopped working.
    2.What did you try
    I tried reducing the amount of models, tried to increase the wait() time because maybe the player doesn’t spawn as fast as the script happens.
    Here is the script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local screengui = script.Parent.Parent
local part = game.Workspace.obby1
local CamPart = game.Workspace.CamPart -- The part that camera changes its view to
local currentcamera = game.Workspace.CurrentCamera
local folder = screengui.Imagebuttons
--table with all of the imagebuttons
local buttontable = {folder.ImageButton, folder.ImageButton1, folder.ImageButton2, folder.ImageButton3, folder.ImageButton4, folder.ImageButton5, folder.ImageButton6, folder.ImageButton7, folder.ImageButton8, folder.ImageButton9, folder.ImageButton10, folder.ImageButton11, folder.ImageButton12, folder.ImageButton13, folder.ImageButton14, folder.ImageButton15, folder.ImageButton16, folder.ImageButton17, folder.ImageButton18, folder.ImageButton19, folder.ImageButton19, folder.ImageButton20}

wait(0.5)
currentcamera.CameraType = Enum.CameraType.Scriptable
currentcamera.CFrame = CamPart.CFrame -- changes the cameras view to the view of the part
currentcamera.FieldOfView = 55 --fov of the camera

buttontable[1].MouseButton1Click:Connect(function()--when the image button is clicked it teleports the player to a part
	wait(0.5)
	humanoidRootPart.CFrame = part.CFrame -- the part that player gets teleported to
	currentcamera.CFrame = character.Head.CFrame
	currentcamera.CameraType = Enum.CameraType.Custom
end)

I think maybe the fix would be to make the script wait until the player spawns in.

So what you’re saying is that it doesn’t work when you first set it or when you click the button?

2 Likes
  1. Make sure this is running from a LocalScript
  2. Make sure that the campart’s Transparency is 1, CanCollide is false, and is Anchored.
  3. The LocalScript Must be a descendant of StarterGui or StarterCharacterScripts or it won’t work.
  4. Try using :WaitForChild when getting the camera in workspace.
  5. Make sure the campart is close enough for it to load into the workspace, as Roblox doesn’t load in things too far away to improve performance.
  6. I tried experimenting with some things, and you don’t need to wait at all… I’m not sure what’s going on, but this basic local script in StarterGui worked…
local camera = workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.campart.CFrame
2 Likes

Have you checked the output? There may be errors related to the script

1 Like

I actually don’t know why it happened but not it works, i had the script inside startergui before and it didn’t work so i moved it to the workspace. Now i followed your steps and put it inside starter gui and it just worked. Thank you for your help.