Help make Camera constantly Update

Hello, i have a script where when u die ur camera goes infront of a moving Ai, the part ur camera goes to is rigged to the Moving Ai, when the camera goes to it it works but it doesnt follow the Ai it goes where it first got put to so how to i make it constantly update and follow the block?


local RemoteJumpscare = game:WaitForChild("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("JumpScare")

RemoteJumpscare.OnClientEvent:Connect(function()
	print("Fired")
	local camera = workspace:WaitForChild("Camera")
	local StartingCam = workspace.Monster["Jumpscare Camera"]
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = StartingCam
	camera.CFrame = StartingCam.CFrame
end)

You would from local script need to reference the players camera

like this:

Workspace.CurrentCamera

CurrentCamera references the camera the player is currently using
Then you set parent of CameraSubject (property of CurrentCamera) to the part you want the player to follow.

-- Local script


local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local part = "Reference your part here" 
-- Died function
player.Character:WaitForChild("Humanoid").Died:Connect(function()
	repeat
		task.wait()
	until player.Character:WaitForChild("Humanoid") or player.CharacterAdded:Wait():WaitForChild("Humanoid")

	part:SetAttribute("watching", true)

	task.spawn(function()

		while part:GetAttribute("watching") == true do
			task.wait()
			game:GetService("Workspace").CurrentCamera.CameraSubject = part

		end
	end)
end)

It could probably be done better than what I have right here but thats for you to do

EDIT: Looking back I think its kinda badly explained on my part if this post isn’t helping then feel free to reply and tell me otherwise I’m not gonna bother.

	mouse.Button1Down:connect(function()
	local chr=sp.Parent
	if chr and lasttrigger.Value+cooldown<tick() then
			local t=chr:FindFirstChild("Head")
			
			
			
			
		local h=chr:FindFirstChild("Humanoid")
		if t and h and h.Health>0 then
			if check then
					check=false
					remoteEvent:FireServer(t, mouse.Hit.p)
					
					lasttrigger.Value=tick()
					mouse.Icon="rbxasset://textures\\GunWaitCursor.png"
					
					sp.Handle.Transparency=1
					SaveType = workspace.CurrentCamera.CameraType
					SaveSubject = workspace.CurrentCamera.CameraSubject 
					SaveFOV = workspace.CurrentCamera.FieldOfView
					SaveCFrame = workspace.CurrentCamera.CFrame
					
					workspace.CurrentCamera.CameraType = "Attach"
					workspace.CurrentCamera.CameraSubject = workspace.Crow.Eyes
					workspace.CurrentCamera.FieldOfView = 100
					wait(.1)
					workspace.CurrentCamera.CameraType = "Track"

			else
				
				check = true
				workspace.CurrentCamera.CameraType = SaveType
					workspace.CurrentCamera.CameraSubject = SaveSubject
					workspace.CurrentCamera.FieldOfView = SaveFOV
					workspace.CurrentCamera.CFrame = SaveCFrame
			end	
		end
	end
end)

end
end

This flips back and forth from a birds-eye view to Player. Canabalize it.

Crow - Roblox

You might fix yours by changing this to some canned Camera-type:

camera.CameraType = Enum.CameraType.Scriptable

Sciptable means you are going to have to do EVERYTHING a camera script does.

The other replies in this thread use while loops to update your cameras position. Do not do this.

I recommend using RunService:BindToRenderStep() to update your cameras position to be in front of your model.

First you will need to understand what RenderStepped is - RenderStepped fires every frame before rendering (it is also known as PreRender). BindToRenderStep() is method of RunService that will run a function every RenderStepped, this can later be unbound using UnbindFromRenderStep.

BindToRenderStep takes 3 parameters: name, render priority, and the function you want to run. The name parameter is used to unbind and reference your bind, and priority determines when during the render stepped that your function is fired - in your case we will be using Enum.RenderPriority.Camera.Value (which is 200). The final parameter is self explanatory.

You will need to create your function first, I’ve provided a basic function that will point my camera towards a part.

local target = workspace.Part -- this is the part I want my camera to track.
local camera = workspace.CurrentCamera -- this gets the currently active camera.

local function UpdateCamera()
    -- this function is going to be fired every frame, you should never yield if a function is being fired so often. RenderStepped is not a loop, it will not wait for the function to complete before firing again.
    local partCF = target.CFrame -- we are going to use the targets CFrame as the base for our camera, then we will apply a CFrame offset so the camera is not inside our target.
    local offset = CFrame.new(5, 0, 0) -- this is our offset, this will offset our camera by 5 studs on our targets X axis, you may need to adjust this.
    camera.CFrame = partCF * offset -- the * operator is used to add two CFrame values to one another.

    -- we have completed our function now.
end

Now that you have your function we can use BindToRenderStep to call it every frame. In the code I’ve provided below the Camera will follow our parts position for 5 seconds before changing back to our character.

camera.CameraType = Enum.CameraType.Scriptable -- our cameras CFrame can only be manipulated outside of the camera script if we have the type to Scriptable.
RunService:BindToRenderStep(‘PartFollow’, Enum.RenderPriority.Camera.Value, UpdateCamera)
task.wait(5)
RunService:UnbindFromRenderStep(‘PartFollow’)
camera.CameraType = Enum.CameraType.Custom -- back to the players normal camera type.

You can take this code and modify it to fit your needs, I have just provided a basic example of how you could accomplish your task. I recommend researching RunService more on the DeveloperHub as well.

2 Likes

RenderStepped was made for the purpose of controlling the local player’s character/camera every frame.

Didn’t you post this same question yesterday but with less context? You even got an answer to use on that thread but didn’t follow up.

Tom_atoes provides the correct way of going about this.

1 Like