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 4 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 4 years ago
Edited 4 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.

1local Camera = Workspace.CurrentCamera -- To get the player's camera.
2local CameraPart = -- The part you want to anchor the camera to
3 
4Camera.CameraType = Enum.CameraType.Scriptable
5-- To prevent the player from influencing the camera.
6 
7Camera.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.

1local Part = script.Parent
2local RemoteEvent = Part.RemoteEvent
3 
4Part.Touched:Connect(function(Hit)
5    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) -- To detect the player
6    if Player then
7        RemoteEvent:FireClient(Player)
8    end
9end)

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.

01local RemoteEvent = (Find the RemoteEvent)
02 
03RemoteEvent.OnClientEvent:Connect(function(Player)
04-- When a RemoteEvent activates for a client, it automatically sends the player.
05 
06    -- You must put the camera manipulation code here.
07 
08    -- (The first code)
09 
10end)

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 — 4y
Ad

Answer this question