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

Changing Player Camera Position. Not working?

Asked by 4 years ago

I wanna change the local player camera pos to a set part on my workspace when the player hits the part, I managed to write the script below, which works, but instead of changing only the local player camera pos, it changes all players camera position instead. How can I make it only changes the local player camera?

local camera = workspace.CurrentCamera
local part = workspace.cam

workspace.Test.Touched:Connect(function(hit)
  if game.Players:GetPlayerFromCharacter(hit.Parent)then
  camera.CameraType = Enum.CameraType.Scriptable
  camera.CFrame = part.CFrame
end
end)

The script is local and is storaged under StarterPlayer/StarterPlayerScripts

2 answers

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

You put cam instead on camera Hope this fixes it

    local camera = workspace.CurrentCamera
    local part = workspace.camera

    workspace.Test.Touched:Connect(function(hit)
      if game.Players:GetPlayerFromCharacter(hit.Parent)then
      camera.CameraType = Enum.CameraType.Scriptable
      camera.CFrame = part.CFrame
    end 
end)

If it helped, validate my answer please!

0
What if his camera is named cam in the workspace DuckyRobIox 280 — 4y
0
No josestankor 39 — 4y
0
"cam" is the part which I use to set the camera's new position josestankor 39 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Here's the solution:

Add an if statement to the start of the fuction checking if who touched the part has the same name of the local player, if yes, run your code, else do something that you want or just dont.

The function would look like this:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local part = workspace.camera

workspace.Test.Touched:Connect(function(hit)
    if player.Name == hit.Parent.Name then
        if game.Players:GetPlayerFromCharacter(hit.Parent)then
            camera.CameraType = Enum.CameraType.Scriptable
            camera.CFrame = part.CFrame
        end
    end
end)

Sorry for the late response, but if you were having the same issue, np!

Answer this question