I am making a game with the players camera screen facing a certain area with a GUI, after the players hit play and vote for a map, and after the voted map is selected I want the players to be teleported to the destination and the camera goes back to their player AUTOMATICALLY. How can I return the camera to their avatar after they are teleported? What type of script should I put this in?
CODE: This is my intermission and voting code, I haven't teleported players yet, but I will after I return the camera to the player.
while true do local timer = 15 repeat wait() configs.Status.Value = "Intermission: ".. timer wait(1) timer = timer - 1 until timer == 0 configs.Status.Value = "..." wait(1) for i,v in pairs(maps:GetChildren()) do local voteId = v:FindFirstChild("VoteId") if voteId then local intValue = Instance.new("IntValue",rStorage.Votes) intValue.Name = v.Name intValue.Value = 0 rEvents.CreateVote:FireAllClients(v.Name,voteId.Value) end end timer = 10 repeat wait() configs.Status.Value = "Map vote: ".. timer wait(1) timer = timer - 1 until timer == 0 configs.Status.Value = "..." local map local highest = 0 for i,v in pairs(rStorage.Votes:GetChildren()) do if v:IsA("IntValue") then local curMap = maps:FindFirstChild(v.Name) if v.Value > highest and curMap then map = curMap end end end if map then configs.Status.Value = map.Name else map = maps:GetChildren()[1] configs.Status.Value = map.Name end rEvents.RemoveAllVotes:FireAllClients() for i,v in pairs(rStorage.Votes:GetChildren()) do v:Destroy() end wait(3) wait() end
The camera will return to the player near the end, after the maps have been voted.
To return the camera back to the humanoid you have to set the focus property to the humanoid.
Like this:
camera.CameraType = Enum.CameraType.Custom camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
https://developer.roblox.com/en-us/api-reference/property/Camera/CameraSubject
I hope this helps :)
this is actually pretty easy to do you have to set the camera type back to costume AND make the camera subject the player by making the camera subject the player's humanoid so it goes like this :
camera.CameraType = Enum.CameraType.Custom camera.CameraSubject = player.Humanoid
Ignore what the other answers, they are wrong.
here is the code
local camera = game.workspace.Camera camera.CameraType = Enum.CameraType.Custom