What’s the point of creating a fake head if you can just set the CFrame of the Camera to the Head’s CFrame and then lock it in place as in when the player dies? This seems like unnecessary overhead.
Also, don’t use a loop here. Humanoids support events for changes to health or checking for death. Always aim for an event-driven system where possible and avoid loops if they aren’t necessary.
Well, when i die the camera gets the position of the Head but the camera gets static in there, and doesn’t aim the head. And when i respawn, the camera no longer returns to the original position. Something that i want to achieve is a bit similar to the Elemental Battlegrounds Death camera
Could you show a video of what you’re intending to achieve? Not everyone here has played Elemental Battlegrounds so when you say you want to achieve an effect similar to another game, you can’t exactly expect anyone to understand what you’re wanting to achieve. Rather than using another game as reference, it’s must more helpful to demonstrate or show what you mean.
I’m starting to understand what you mean now, you can achieve it via updating the Camera’s CFrame to Head’s CFrame every RenderStepped - no need for a FakeHead.
For reseting it, Connect on CharacterAdded and Disconnect the RenderStepped & most importantly set the CameraType backt to custom.
I’d provide a Script but I’m currently on tablet.
You give it the string name of your bind, you can set this to what you like, a prority of the bind and since you’re doing Camera implementation you should use the Camera priority (Enum.RenderPriority.Camera) & finally the function to bind to RenderStepped
--// Dependencies
local RunService = game:GetService("RunService") --// The service we need
--// Functions
local function cameraUpdate()
--// Update the camera etc
end
--// Binds
RunService:BindToRenderStep(
"CameraUpdate", --// Bind name
Enum.RenderPriority.Camera.Value, --// Priority of the Bind
cameraUpdate --// The function to Bind
)
--// Now you can also do RunService:UnbindFromRenderStep("CameraUpdate")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid") --// Just in case it hasn't been added yet, wait for it
local Camera = workspace.CurrentCamera --// The Camera, fyi you can use the workspace keyword instead of game.Workspace
local RunService = game:GetService("RunService") --// The service we need
--// Functions
local function onDied()
local HeadCFrame = Character.Head.CFrame --// The real head's CFrame
local FakeHead = Instance.new("Part") --// Create our new FakeHead part
FakeHead.CFrame = HeadCFrame --// Set the FakeHead's CFrame to the real head's CFrame
FakeHead.Anchored = true --// Make sure it's Anchored
FakeHead.Transparency = 1 --// Make it Transparent so you won't see it
FakeHead.CanCollide = false --// Ensure no collisions
FakeHead.Parent = workspace --// Parent it to workspace
Camera.CameraType = Enum.CameraType.Scriptable --// Change the type of the camera to allow us to edit it
Camera.CameraSubject = FakeHead --// Make the subject of the camera our new FakeHead
Camera.CFrame = FakeHead.CFrame --// Make the CFrame of the camera the same as the FakeHead
Camera.Focus = CFrame.new(FakeHead.CFrame.LookVector) --// Yet also make it face the same way, since LookVector is a Vector3 and Focus requires a CFrame we make it a CFrame
end
--// Connections
Humanoid.Died:Connect(onDied)
--// Binds
RunService:BindToRenderStep("CameraUpdate",Enum.RenderPriority.Camera.Value,onDied)
I did this and it didn’t worked, this made the player be in first person always, and the head wasn’t anchored.
Sorry for the late reply, there were a few problems with the last one so I’ve written up a new one.
The comments should run you through what each part does:
--// Dependencies
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--// Variables
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local BindSetup = false --// This will be a signifier of if it's setup yet/properly
--// Functions
local function deathCamera(character)
local humanoid = character:WaitForChild("Humanoid") --// Wait for the Humanoid incase it hasn't loaded yet
if BindSetup then --// If it's been setup
RunService:UnbindFromRenderStep("FakeHeadBind") --// Unbind the updater
Camera.CameraSubject = humanoid --// Set the subject back to the Humanoid
Camera.CameraType = Enum.CameraType.Custom --// Allow them to customise their camera
BindSetup = false --// Now it hasn't been setup
end
humanoid.Died:Connect(function() --// When the Humanoid dies
local RealHead = character.Head
local FakeHead = Instance.new("Part") --// Create the fake head
FakeHead.Anchored = true
FakeHead.Transparency = 1
FakeHead.CanCollide = false
FakeHead.CFrame = RealHead.CFrame
FakeHead.Parent = character
FakeHead.Parent = workspace
Camera.CameraType = Enum.CameraType.Scriptable --// Allows for the editing of CFrames, subjects etc
Camera.CameraSubject = FakeHead --// Set the subject to the fake head
BindSetup = true --// It has now been setup
RunService:BindToRenderStep("FakeHeadBind", Enum.RenderPriority.Camera.Value, function() --// Every frame on the priority of Camera
if character and character:FindFirstChild("Head") then --// If their Head still exists
FakeHead.CFrame = RealHead.CFrame --// Set their fake head's CFrame to the real head's CFrame
Camera.CFrame = FakeHead.CFrame --// You can adjust this to your liking
Camera.Focus = CFrame.new(FakeHead.CFrame.LookVector) --// Make the Focus the same way as the fake head's facing
end
end)
end)
end
if LocalPlayer.Character then --// If they've already spawned
deathCamera(LocalPlayer.Character)
end
LocalPlayer.CharacterAdded:Connect(deathCamera) --// When they do spawn
I tested this in studio and seems to be woring perfectly. I hope this is the effect you’re going for.
Well, this is still not working, maybe because i have FilteringEnabled? or i set the script in a wrong carpet? (StarterCharacterScripts). Well, i just can say that the FakeHead is not getting removed, may cause lag in the game…
Oh jeez I forgot to say, this needs to be in StarterPlayerScripts as it’s connecting upon CharacterAdded (scripts in StarterCharacterScripts will not ever fully connect on CharacterAdded as it’s fired before the script starts running.)
That’s what I programmed it to do, and that’s what I thought you were trying to achieve.
On this line inside the BindToRenderStep it does this:
FakeHead.CFrame = RealHead.CFrame
However, for what you want to do you can utilise the CFrame.new constructor and one of it’s overloads where you give the position, and the lookAt position.