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

How do I make a part change the camera subject when it's touched?

So I have a camera attached to a part and it can't move, like I wanted. But I need to make it so that a part can change the camera subject and still make it so the camera can't move.

This is the script I used to attempt to change the camera subject:

function onTouch(hit)
local	 cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.Room1
cam.CameraType = Enum.CameraType.Scriptable

cam.CoordinateFrame = CFrame.new(game.Workspace.Room1.Position)
end

Which I have put into the part that is supposed to change the camera subject by changing it to a new camera subject. (In this case: a Part named "Room1") When I tried this, it didn't even give me an error, so i'm not sure what's happening here.

Now, here's the script I used to lock the camera in place, which is a Local Script in Starter Gui:

repeat wait() until game.Players.LocalPlayer.Character
local cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.Start
cam.CameraType = Enum.CameraType.Scriptable

cam.CoordinateFrame = CFrame.new(game.Workspace.Start.Position)

Which works just fine! Can someone please tell me how I can either fix the script I put into the part so it changes the camera subject and still make the camera immobile or add in new lines that can do the same function?

(Start is the name of the part it's attached to, ignore that.)

1 comment

0

I'm not sure you can use .CoordinateFrame, try using .CFrame instead.

1 answer

✓ Accepted answer

The use of .CoordinateFrame has been deprecated. Try this instead.

function onTouch(hit)
local    cam = game.Workspace.CurrentCamera
cam.CameraSubject = game.Workspace.Room1
cam.CameraType = Enum.CameraType.Scriptable

cam.CFrame = CFrame.new(game.Workspace.Room1.Position)
end

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