CCTV track the Player's Position

I was trying to make a fixed camera view which track the player’s location when they moving around the room kinda like a CCTV cam
currently I manage to make swapping the camera work but the part doesn’t track the player location

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local cameraMan = workspace:FindFirstChild("CameraMan")
local Destination = workspace:FindFirstChild("TeleportDestination")

local cctv = script.Parent.CCTV
local back = script.Parent.Return
local Looking = false

cctv.MouseButton1Click:Connect(function() -- button for CCTV cam
	Looking = true
	rootPart.CFrame = Destination.CFrame
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = cameraMan.CFrame
end)


while Looking == true do -- my Attempt at making the camera track the player's location
	cameraMan.CFrame = CFrame.lookAt(cameraMan.Position, rootPart.Position)
end

back.MouseButton1Click:Connect(function() -- button for swap cam back
	Looking = false
	rootPart.CFrame = workspace:FindFirstChild("SpawnLocation").CFrame
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CFrame = Camera.CFrame
end)

1 Like
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local rootPart = Character:FindFirstChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local cameraMan = workspace:FindFirstChild("CameraMan")
local Destination = workspace:FindFirstChild("TeleportDestination")

local cctv = script.Parent.CCTV
local back = script.Parent.Return
local Looking = false

cctv.Activated:Connect(function() -- button for CCTV cam
	Looking = true
	rootPart.CFrame = Destination.CFrame
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = cameraMan.CFrame
end)

game:GetService("RunService").RenderStepped:Connect(function()
 if Looking then
	cameraMan.CFrame = CFrame.lookAt(cameraMan.Position, rootPart.Position)
	Camera.CFrame = cameraMan.CFrame
end
end)

back.Activated:Connect(function() -- button for swap cam back
	Looking = false
	rootPart.CFrame = workspace:FindFirstChild("SpawnLocation").CFrame
	Camera.CameraType = Enum.CameraType.Custom
	Camera.CFrame = Camera.CFrame
end)
1 Like

I forget Runservice existed thank you! it working just fine

1 Like

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