Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Changing Player Camera Position. Not working?

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

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!

3 comments

0

What if his camera is named cam in the workspace

0

No

0

"cam" is the part which I use to set the camera's new position

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.