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

why CameraSubject does not change???

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!

1 comment

0

couple of things, is this a script or local script, and where is it located?

1 answer

✓ Accepted answer

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)

2 comments

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!

0

Why does it have to be in StarterGui?

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