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

How do I put a player's camera back to themselves after changing it?

Asked by 5 years ago

I'm making a camera manipulation intro to my new game and I'm honestly puzzled on this. This is the current script I have:

local cam = workspace.CurrentCamera local camPart = workspace:WaitForChild("Cam")

cam.CameraType = Enum.CameraType.Scriptable cam.CFrame = camPart.CFrame + cam.CFrame.lookVector * 2 cam.CameraSubject = workspace:WaitForChild("Cam") camPart.Transparency = 1

(Cam is the part I'm using for my camera) how would I change it back to humanoid?

2 answers

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
5 years ago
Edited 5 years ago

You can reset the camera back to the character by doing this:

if game.Players.LocalPlayer.Character then
    cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end
cam.CameraType = Enum.CameraType.Custom

It first checks if the character exists. Then, it sets the camera subject to the corresponding humanoid. Finally, it sets the camera type to custom (this allows the player to choose their own camera mode). You may change this if you had a setting for the CameraType before.

0
Thanks so much man! I'm making a "Robloxity" Remake and I needed this for the intro =D nickos3 4 — 5y
0
Mans are grinding. Zafirua 1348 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

the way you can do this is by first setting the camera subject and then the cameratype back to custom.

local cam = workspace.CurrentCamera 
local camPart = workspace:WaitForChild("Cam")

cam.CameraType = Enum.CameraType.Scriptable 
cam.CFrame = camPart.CFrame + cam.CFrame.lookVector * 2 
cam.CameraSubject = workspace:WaitForChild("Cam") 
camPart.Transparency = 1

delay(5,function()
    cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    cam.CameraType = Enum.CameraType.Custom
end)

So this basically did everything you did in the script above (please use codeblocks) and makes a coroutine 5 seconds after the

cam.CameraType = Enum.CameraType.Scriptable 
cam.CFrame = camPart.CFrame + cam.CFrame.lookVector * 2 
cam.CameraSubject = workspace:WaitForChild("Cam") 
camPart.Transparency = 1

runs. In the coroutine, it makes the player the camera subject and makes the camera type "custom"

0
Also, I might be wrong about the delay function creating a coroutine, but I'm just basing that off a RobloxU tutorial by StickMasterLuke 4 years ago theking48989987 2147 — 5y
0
It's not called a coroutine; it's called a function. Coroutines are just an implementation detail here. RayCurse 1518 — 5y
0
is there a link? theking48989987 2147 — 5y

Answer this question