Camera part for local players

Hi devs ! I tried to make a script that change the player camera to a part but it only work when i do “FireAllClient” but i want that change the camera to the player who touch the part ( so in local )

Here is what i want in local :

Here is my scripts :


local camera = workspace.Camera

local part = workspace.PartCameraOui


while true do


camera.CameraType = Enum.CameraType.Scriptable

camera.CFrame = part.CFrame



When the player touch the part



Tnks !

If you intend to fire to a Single Player, you use FireClient instead of FireAllClients, But with this Change, you would need the Player as your first Argument, You can do a simple check by using game.Players:GetPlayerFromCharacter to check if the Item is a Players Character, When you use this function, you would need to check if the Value returned anything, as if the Function did not return the Player, it will return as nil because you either didnt get a Character, we can check like this:

local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the Player based on the Touching Parts Parent (A Model?)

if Player then -- if the Item we looked through is a Player
    CameraChange:FireClient(Player) -- Fires Event for Player only.

To Explain, the Touched Event returns the Part that touched the Main Par (which we will refer to as hit)t, and not the Model that touched it, in order to check for the Model (which can be the Model of the Character) we would need to check the hits Parent which could be anything, but Doing this we can then check if the “Model” is a Player or not by using the GetPlayerFromCharacter function to get the Player based off of the Character, If the Item does not match a Players Character, it is considered nil, and we cant give a nil Value to FireClient as that will result in an error. So we add an if statement to check if the Item we checked is actually a Character for a Player or not, and if that statement is true, we will then fire the RemoteEvent for that Specific Player.

Its Supposed to be workspace.CurrentCamera just so you know.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.