Player camera when touching part

I need help trying to get the player’s camera once they touch a part so that I can move it.


image

I am trying to get the player’s camera when they touch a part(EnterPart).
I’ve tried it with a Script and LocalScript but couldn’t get it to work.

I have looked for solutions but none of them have worked.

1 Like

Try using this GetPlayer() function instead in a LocalScript. What this code does is that as well as changing the CameraType and CFrame, it also change the CameraSubject to the part you want the player’s camera to be at.

local function GetPlayer(otherPart)
	local Character = otherPart.Parent
	local Player = game:GetService("Players"):GetPlayerFromCharacter(Character)
	
	if Player == nil then return end
	
	local camera = game.Workspace.CurrentCamera
	
	if camera.CameraType ~= Enum.CameraType.Scriptable then
		camera.CameraType = Enum.CameraType.Scriptable
	end
	
	camera.CameraSubject = FCamera
	camera.CFrame = FCamera.CFrame
end
1 Like

What I would do would probably create a remote event then fire the remote event to the client who touched the part, then from a local script edit the camera

I would probably look something like this:
-server script

local enterPart = script.Parent

local remoteEvent = -- Path to the remote event

enterPart.Touched:Connect(function(otherPart)
    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
    if player then remoteEvent:FireClient(player)
end)

-local script

local remoteEvent = --path to remote event

remoteEvent.OnClientEvent:Connect(function()
    local camera = workspace.Camera
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = (workspace:FindFirstChild('FCamera') or workspace:WaitForChild('FCamera')).CFrame
end)
1 Like

Thank you J_Angry & Dragon_bloxy for helping.