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

How can I automatically return the camera to a player?

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

0
Thanks! StirSavvy 38 — 3y
0
No problem! IceyTazeForLife 253 — 3y
Ad
Log in to vote
0
Answered by
crueluu 169
3 years ago
Edited 3 years ago

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
0
Thanks, but in my sript it says an error on 'camera.cameratype' and it says expected assignment or function call StirSavvy 38 — 3y
0
can you give me your whole code so i can investigate? crueluu 169 — 3y
0
Sure! I'll add it to the question StirSavvy 38 — 3y
0
It has been added. StirSavvy 38 — 3y
View all comments (2 more)
0
@crueluu == is used to compare two values, not assign a value to variable. It should be camera.CameraType = "Custom" IceyTazeForLife 253 — 3y
0
yeah sorry, typo crueluu 169 — 3y
Log in to vote
0
Answered by 3 years ago

Ignore what the other answers, they are wrong.

here is the code

local camera = game.workspace.Camera
camera.CameraType = Enum.CameraType.Custom
0
@Itzlewis99 It doesn't make a difference.  IceyTazeForLife 253 — 3y
0
Also what's wrong with me and @crueluu 's code? IceyTazeForLife 253 — 3y
0
your code makes the camera look at the player Itzlewis99 26 — 3y

Answer this question