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

Way to switch between cameras?

Asked by 3 years ago

I want to make it so that when a player touches a block it teleports them to an area and changes to a camera that shows the area exactly the way I want. I got the teleporting part but how can I switch the camera to a camera object inside a brick?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

To change a specific player's camera, you need to use a LocalScript, because you need to use CurrentCamera, which can only be accessed by a LocalScript.

In a LocalScript.

local Camera = Workspace.CurrentCamera -- To get the player's camera.
local CameraPart = -- The part you want to anchor the camera to

Camera.CameraType = Enum.CameraType.Scriptable
-- To prevent the player from influencing the camera.

Camera.CFrame = CameraPart.CFrame

To make the function activate when playing a piece, you can create a RemoteEvent inside the piece you want, create the base code for when the piece is played, and trigger the event for the specific customer.

local Part = script.Parent
local RemoteEvent = Part.RemoteEvent

Part.Touched:Connect(function(Hit)
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- To detect the player
    if Player then
        RemoteEvent:FireClient(Player)
    end
end)

Now you need a Local Script inside this part that detects that RemoteEvent was triggered as a client, so put the first code inside the function.

local RemoteEvent = (Find the RemoteEvent)

RemoteEvent.OnClientEvent:Connect(function(Player)
-- When a RemoteEvent activates for a client, it automatically sends the player.

    -- You must put the camera manipulation code here.

    -- (The first code)

end)

I don't know if there is another way to do this, but that was the solution I found :)

Any questions, you can ask.

:)

0
Thanks! bogotesr 2 — 3y
Ad

Answer this question