Create a fake head for my character

I’m creating a camera death effect, which is only for a first person player, well, this is the script:

game.Players.LocalPlayer.CharacterAdded:wait()
wait()
local character = game.Players.LocalPlayer.Character
local hum = character:FindFirstChild("Humanoid")
local FakeHead = "?"
while true do
  	wait(.01667)
  	if hum.Health == 0 then
		game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		game.Workspace.CurrentCamera.CFrame = CFrame.new((character.FakeHead.CFrame * CFrame.new(0, 5, 0)).Position, Head.Position)
	end
end

I want to special thanks imalex4 for the script, by the way, if you can see there’s a local called FakeHead, i want to create a fake head where if you die, the camera gets attached to it and that fakehead gets anchored and be in the position of the head before the player dies, an example what i want to achieve is like when you die in Elemental Battlegrounds, but this time the camera is in first person, my question is how do i instance or create a fakehead in this script? (local script). Thanks :+1:

2 Likes

Well, if you had the LocalScript in StarterCharacterScripts then it’ll be placed inside the Character - therefore no need to get the character as script.Parent is the character.

You can get rid of that while loop as well, there’s the Huamanoid.Died event.

Now for placing that FakeHead, it’s possible to use Instance.new to create a new Part & set it to the real Head’s CFrame inside the Died event.

Putting all of that into action:

--// Variables
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

--// 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)
5 Likes

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.

2 Likes

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

Creating a fake head allows me to edit and modify your camera much easier, in case I want to add a more movement effect.

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.

The ROBLOX recorder is using WMV, i can’t upload this type of files here and i don’t know how to convert a file, or a recorder to my device.

1 Like

Use a file converter or a different application capable of recording, such as ShareX.

1 Like

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.

Unless I misunderstood you again?

How do i connect and disconnect RenderStepped?

Well using the event from RunService, :Connect’ing to a RBXScriptSignal (an event) returns a RBXScriptConnection which can be :Disconnect’d.

However, I’d personally use BindToRenderStep and the corresponding UnbindFromRenderStep

How do i use BindToRenderStep? i saw the post at the dev hub, but i didn’t understand it

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

I misunderstood again… Could you provide me the code please? :slight_smile:

--// 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.

@return_end1

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.

1 Like

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.)

1 Like

The problem now is that “FakeHead” is something like “welded” in the head, and i want to the FakeHead stay in the air. to aim the head.