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

How can I automatically return the camera to a player?

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.

3 answers

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

6 comments

0

Thanks, but in my sript it says an error on 'camera.cameratype' and it says expected assignment or function call

0

can you give me your whole code so i can investigate?

0

Sure! I'll add it to the question

0

It has been added.

0

@crueluu == is used to compare two values, not assign a value to variable. It should be camera.CameraType = "Custom"

0

yeah sorry, typo

Ignore what the other answers, they are wrong.

here is the code

local camera = game.workspace.Camera
camera.CameraType = Enum.CameraType.Custom

3 comments

0

@Itzlewis99 It doesn't make a difference. 

0

Also what's wrong with me and @crueluu 's code?

0

your code makes the camera look at the player

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