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

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

Asked by 6 years ago
Edited 6 years ago

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.)

0
I'm not sure you can use .CoordinateFrame, try using .CFrame instead. Le_Teapots 913 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
Ad

Answer this question