Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why CameraSubject does not change???

Asked by 5 years ago
Edited 5 years ago

So i made a script: when the player clicks a block, it changes the camera's Subject to the clicked block, but for some reason it just does not work, this is the script:

local camera = workspace.CurrentCamera

function GoBuild()
    camera.CameraSubject = script.Parent
end
script.Parent.ClickDetector.MouseClick:Connect(GoBuild)

Its located here: https://prnt.sc/ms2dtm ...

For some reason it does not even leave a console error, I would appreciate if someone could help me :D!

0
couple of things, is this a script or local script, and where is it located? theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Ok so this code is perfectly fine, however, you need to make sure this is in a LocalScript for it to run.

You can also place the function connection in the same line as its definition.

CameraSubject changes a camera's focus, if you also want to change its positon, you need to add the camera's CFrame property.

Revised LocalScript under StarterGui

local camera = workspace.CurrentCamera
local part = workspace.Part -- whatever "script.Parent" is

part.ClickDetector.MouseClick:Connect(function()
    camera.CameraSubject = part
    camera.CFrame = part.CFrame
end)
1
Ok so i just found out that my script wasnt supposed to be inside a part, also thank you for the CFrame tip , i did not know about that, thanks :D! Igoralexeymarengobr 365 — 5y
0
Why does it have to be in StarterGui? squidiskool 208 — 3y
Ad

Answer this question