Camera dosnt work ;(

Hi guys. I want the player camera to be moved to Part so I can watch the action from a third person perspective. Nothing happens.

da screens:
image

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent

local function moveCamera(player)
	local originalCamera = player.Camera
	player.Camera = camPenicillin

	print("Camera moved to")

	wait(10)

	player.Camera = originalCamera

	print("Camera returned")
end

proximityPrompt.TriggerEnded:Connect(function()
	local player = Players.LocalPlayer
	if player then
		moveCamera(player)
	else
		print("LocalPlayer not found")
	end
end)
2 Likes

What prints are fired when this is ran? lol why does this have 3 likes

3 Likes

The way to get the players camera is localplayer.CurrentCamera not localplayer.camera, also you will need to set the camera to scriptable

1 Like

LocalScripts don’t run in Workspace

1 Like

But how can I depict this in a script? Please help me

1 Like

First create a serverscript into the proximity prompt:

local Proxy = script.Parent

local Event = --Any event location

Proxy.Triggered:Connect(function(playerwhotriggered)
	print('I got triggered')
	Event:FireClient(playerwhotriggered)
end)



Client

local Event =nil --Any event location

local player = game.Players.LocalPlayer

local Player_Camera = workspace.CurrentCamera

local part_camera = nil -- The part that you want as camera
local rs = game:GetService("RunService")
Event.OnClientEvent:Connect(function()
	Player_Camera.CameraType = Enum.CameraType.Custom
	rs.RenderStepped:Connect(function()
		Player_Camera.CFrame = part_camera.CFrame
	end)
	
end)
1 Like

It really works. Thank you very much!

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local CamPos = ReplicatedStorage:WaitForChild("Cam"):WaitForChild("CamSpore")
local Event = CamPos
local CamSpore = Workspace:WaitForChild("Spore room")

local player = Players.LocalPlayer
local Player_Camera = Workspace.CurrentCamera
local part_camera = CamSpore:WaitForChild("Camera")
local rs = game:GetService("RunService")

local function returnCameraToPlayer()
	local originalCFrame = Player_Camera.CFrame
	rs.RenderStepped:Connect(function()
		Player_Camera.CFrame = part_camera.CFrame
	end)
	wait(2)  
	Player_Camera.CFrame = originalCFrame
end

Event.OnClientEvent:Connect(returnCameraToPlayer)

There is one problem. When I want to return the camera to the player, nothing happens. No errors in output

2 Likes

Just do Camera.CameraType = Enum.CameraType.Custom and disconnect the Player_Camera.CFrame = part_camera.CFrame
function

1 Like

Does this work out for ya?

local Players = game:GetService("Players")
local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent

local function moveCamera(player)
	local originalCameraType = workspace.CurrentCamera.CameraType
	local originalCameraCFrame = workspace.CurrentCamera.CFrame

	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	workspace.CurrentCamera.CFrame = CFrame.new(camPenicillin.Position)

	print("Camera moved to CamPenicillin")

	wait(10)

	workspace.CurrentCamera.CameraType = originalCameraType
	workspace.CurrentCamera.CFrame = originalCameraCFrame

	print("Camera returned to original position")
end

proximityPrompt.TriggerEnded:Connect(function()
	local player = Players.LocalPlayer
	if player then
		moveCamera(player)
	else
		print("LocalPlayer not found")
	end
end)
2 Likes

Or this maybe

local Camera = game.Workspace.CurrentCamera
local Part2 = game.Workspace:FindFirstChild("Part2")

if Part2 then
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = CFrame.new(Part2.Position)
end
``
2 Likes

NOTE: You can change the name Part2 To the name that the part uses that you want to use to change the camera position.

2 Likes

Bro thank you very much but I already found a solution. I had to do was disable renderSteppedConnection

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")

local CamPos = ReplicatedStorage:WaitForChild("Cam"):WaitForChild("CamSpore")
local Event = CamPos
local CamSpore = Workspace:WaitForChild("Spore room")

local player = Players.LocalPlayer
local Player_Camera = Workspace.CurrentCamera
local part_camera = CamSpore:WaitForChild("Cameraa")
local rs = game:GetService("RunService")

local renderSteppedConnection

Event.OnClientEvent:Connect(function()
	Player_Camera.CameraType = Enum.CameraType.Custom
	player.Character:WaitForChild("HumanoidRootPart").Anchored = true

	renderSteppedConnection = rs.RenderStepped:Connect(function()
		Player_Camera.CFrame = part_camera.CFrame
	end)

	wait(5)

	Player_Camera.CameraType = Enum.CameraType.Custom
	renderSteppedConnection:Disconnect()  
	player.Character:WaitForChild("HumanoidRootPart").Anchored = false
end)
1 Like

you need to change a few things

  1. Use current camera
    local Camera = workspace.CurrentCamera
  2. Change camera type in function “MoveCamera”
    Camera.CameraType = Enum.CameraType.Custom
  3. put local script to StarterPlayerScripts

full script :

local Camera = workspace.CurrentCamera

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent

local function moveCamera(player)
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame =  camPenicillin.CFrame

	print("Camera moved to")

	wait(10)
	
	Camera.CFrame = player.Character.HumanoidRootPart.CFrame
	Camera.CameraType = Enum.CameraType.Custom

	print("Camera returned")
end

proximityPrompt.TriggerEnded:Connect(function()
	local player = Players.LocalPlayer
	if player then
		moveCamera(player)
	else
		print("LocalPlayer not found")
	end
end)

image
is the direction of the CFrame
you need to set it to the place where the camera is to be pointed

If something still doesn’t work, write to me

1 Like

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