Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Simple Camera Script Not working? (only works in StarterGui) [Easy to fix!]

so i made this simple camera script that doesn't work when using ClickDetector, but works perfectly when i place it in StarterGUI

local script inside a part v

   script.Parent.ClickDetector.MouseClick:Connect(function()
    
local camera = workspace.CurrentCamera
wait(.1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.Cam1.CFrame
    
   end)

local script inside starterGui v

local camera = workspace.CurrentCamera
wait(.1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace.Cam1.CFrame

6 comments

0

you forgot the e at the end of Scriptable on line 5

0

my bad, but the script still isnt working

0

probably because you put a local script in the workspace where they do not run. https://developer.roblox.com/api-reference/class/LocalScript

0

dosent work if its a local or a global script

0

You're missing CameraSubject.

0

move the local script to a place it can run. I did not say to chenage it to a server script. The server does not have access to the players camera.

1 answer

General Practice

Use :WaitForChild() to make sure that something exists before using or changing it.

If you do not set the focus of the CurrentCamera's CFrame using CFrame.new(position1, position2) then you need to use the CameraSubject property of the Current Camera to set its focus.

Issues

You need to place the LocalScript inside an area that is directly used by the Client (such as the StarterGui) in order for it to run correctly (Workspace is NOT one of these places)

In order to get the ClickDetector you will have to manually input its location, so for my example below, the ClickDetector is in a part named "ClickPart" which is in the Workspace, and upon being clicked, will cut to the view of the part "Cam1" which is also in the Workspace.

Revised Local Script under StarterGui

local camera = workspace.CurrentCamera
local campart = workspace:WaitForChild("Cam1")
local click = workspace:WaitForChild("ClickPart"):WaitForChild("ClickDetector")

click.MouseClick:Connect(function()
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = campart.CFrame
    camera.CameraSubject = campart
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.