How can I make a Roblox player's camera follow a floating username animation on rejoin?

I’m working on a Roblox game where players leave a “fallen body” with a floating username above it. When the player rejoins, I want their camera to smoothly follow the floating username animation (CFrames stored in a Frames folder, with settings in a Settings folder).

I already have: The username clone with a Frames folder (all CFrameValues) and Settings folder with Loop and Reference values.

I want:

  • The client camera to follow the username along the CFrames when they rejoin.
  • The animation to optionally loop if Loop is true.

How can I properly bind the camera to follow the username clone using RunService or another method? Any example or guidance would help!

local BodyManager = {}

local DSS = game:GetService("DataStoreService")
local DataStore = DSS:GetDataStore("Player_Bodies")
local MessagingService = game:GetService("MessagingService")

local Players = game:GetService("Players")
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local TeleportService = game:GetService("TeleportService")
local ServerStorage = game:GetService("ServerStorage")
local Character_Reserves = ServerStorage.CharacterReserves

local PowerOn_Anim = "rbxassetid://90885075696141"
local PowerOff_Anim = "rbxassetid://122053069775967"
local Idle_Anim = "rbxassetid://115055774181265"

-- Save player data
local function SaveData(Player)
	local Data = {
		JobId = game.JobId,
		TimeStamp = os.time(),
	}
	local Save, err = pcall(function()
		DataStore:SetAsync(Player.UserId, Data)
	end)
	if not Save then
		warn(err)
	else
		print(Player.Name.."'s character has been reserved!")
	end
end

-- Remove saved player data
local function RemoveData(UserId)
	local Removed, err = pcall(function()
		DataStore:RemoveAsync(UserId)
	end)
	if not Removed then
		warn(err)
	else
		print(UserId.." character has been destroyed!")
		return true
	end
end

-- Get saved data
local function GetData(UserId)
	for i = 1, 3 do
		local success, Data = pcall(function()
			return DataStore:GetAsync(UserId)
		end)
		if success and Data then
			return Data
		end
		task.wait(1)
	end
	return nil
end

-- Play PowerOn animation
local function PlayAnim(Humanoid,Id)
	local Animator = Humanoid:FindFirstChildOfClass("Animator")
	if not Animator then
		return
	end
	if Id == "" then
		return
	end
	local Anim = Instance.new("Animation")
	Anim.AnimationId = Id
	local track = Animator:LoadAnimation(Anim)
	track:Play()
	return track
end

-- Update the reserve in storage
local function UpdateReserve(Character)
	if not Character then
		return
	end
	if Character_Reserves:FindFirstChild(Character.Name) then
		Character_Reserves:FindFirstChild(Character.Name):Destroy()
	end
	local Clone = Character:Clone()
	Character.Parent = Character_Reserves
end

-- When player leaves, create body and make it fallen
local function onPlayerRemoving(Player)
	if Player:GetAttribute("Teleporting") then
		return
	end
	local Spirit = script.Spirit:Clone()
	local Clone = Character_Reserves:FindFirstChild(Player.Name)
	if not Clone then
		return
	end

	Clone:SetAttribute("OwnerId", Player.UserId)

	local Head = Clone:WaitForChild("Head")

	-- Set PlatformStand so the body stays fallen
	local Humanoid = Clone:FindFirstChildOfClass("Humanoid")
	PlayAnim(Clone:WaitForChild("Humanoid"),PowerOff_Anim)
	task.delay(3,function()
		PlayAnim(Clone:WaitForChild("Humanoid"),Idle_Anim)
	end)
	if Humanoid then
		Humanoid.PlatformStand = true
		Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end

	-- Spirit/name effect
	Spirit.Parent = workspace

	Spirit.BillboardGui.PlayerName.Text = Player.Name
	Spirit.Position = Vector3.new(Head.Position.X, Head.Position.Y, Head.Position.Z)
	if Head:FindFirstChildOfClass("BillboardGui") then
		Head:FindFirstChildOfClass("BillboardGui"):Destroy()
	end

	Clone.Parent = workspace

	task.spawn(function()
		for i=1,100 do
			Spirit.Position += Vector3.new(0,1,0)
			task.wait(.015)
		end
		for i=1,100 do
			Spirit.Position += Vector3.new(0,0.7,0)
			task.wait(.008)
		end
		Spirit:Destroy()
	end)

	SaveData(Player)
end

-- Track alive servers
local AliveServers = {}

local function isJobIdAlive(targetJobId)
	local lastPing = AliveServers[targetJobId]
	return lastPing and os.time() - lastPing <= 20
end

-- Camera follow helper
local function StartCameraFollow(player, hrp)
	local cam = workspace.CurrentCamera
	local animFolder = script:WaitForChild("CameraFollowAnim") -- folder containing Frames & Settings
	local framesFolder = animFolder:WaitForChild("Frames")
	local settings = animFolder:WaitForChild("Settings")
	local loop = settings:WaitForChild("Loop").Value
	local reference = settings:WaitForChild("Reference")
	local hasReference = reference:FindFirstChild("Has") and reference.Has.Value

	if hasReference then
		task.spawn(function()
			repeat
				for _, frame in ipairs(framesFolder:GetChildren()) do
					if frame:IsA("CFrameValue") then
						cam.CFrame = frame.Value + hrp.Position -- adjust offset if needed
						task.wait() -- tweak speed as needed
					end
				end
			until not loop
		end)
	end
end

-- When player joins
local function onPlayerAdded(Player)
	local Spirit = script.Spirit
	Player.CharacterRemoving:Connect(UpdateReserve)
	local function CharacterAdded(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			if Player then
				Player:LoadCharacter()
			end
		end)

		-- Add floating name above head
		if not Character:WaitForChild("Head"):FindFirstChildOfClass("BillboardGui") and not Character:FindFirstChild("Spirit") then
			local Clone = Spirit.BillboardGui:Clone()
			Clone.PlayerName.Text = Player.Name
			Clone.Parent = Character:WaitForChild("Head")
		end
	end

	local Data = GetData(Player.UserId)
	if Data then
		if Data.JobId == game.JobId then
			local OldBody = workspace:FindFirstChild(Player.Name)
			if not OldBody then
				for _,v in pairs(workspace:GetChildren()) do
					if v:GetAttribute("OwnerId") == Player.UserId then
						OldBody = v
					end
				end
			end
			if OldBody then
				Player.Character = OldBody
				local Humanoid = OldBody:FindFirstChildOfClass("Humanoid")
				if Humanoid then
					Humanoid.PlatformStand = false
					Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
				end
				local Head = OldBody.Head
				local Clone = Spirit:Clone()
				Clone.BillboardGui.PlayerName.Text = Player.Name
				local HeadPos = Head.Position
				Clone.Position = Vector3.new(HeadPos.X, HeadPos.Y+30, HeadPos.Z)
				Clone.Parent = Player.Character
				task.spawn(function()
					for i=1,100 do
						Clone.Position -= Vector3.new(0,.2,0)
						task.wait(.01)
					end
					for i=1,100 do
						Clone.Position -= Vector3.new(0,.1,0)
						task.wait(.01)
					end
					if not Player.Character:WaitForChild("Head"):FindFirstChildOfClass("BillboardGui") then
						Clone.BillboardGui.Parent = Head
						Clone:Destroy()
					end
					for _,v in pairs(OldBody:FindFirstChildWhichIsA("Humanoid"):GetPlayingAnimationTracks()) do
						if v.IsPlaying then
							v:Stop()
						end
					end

					-- Play PowerOn, then respawn at same pos/rot
					local track = PlayAnim(Player.Character:WaitForChild("Humanoid"),PowerOn_Anim)
					if track then
						track.Stopped:Wait()
				
						if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
							local hrp = Player.Character.HumanoidRootPart
							local cf = hrp.CFrame
							Player:LoadCharacter()
							local newChar = Player.Character or Player.CharacterAdded:Wait()
							local newHrp = newChar:WaitForChild("HumanoidRootPart")
							newHrp.CFrame = cf -- restore pos+rotation

							-- Start camera follow
							StartCameraFollow(Player, newHrp)
						end
					end
				end)
			else
				RemoveData(Player.UserId)
				Player:LoadCharacter()
			end
		else
			Player:SetAttribute("Teleporting", true)
			local Teleported = false
			if isJobIdAlive(Data) then
				for i = 1, 3 do
					print("Attempting to teleport "..Player.Name)
					local attempt, err = pcall(function()
						TeleportService:TeleportToPlaceInstance(game.PlaceId, Data.JobId, Player)
					end)
					if attempt then
						print("Teleporting "..Player.Name)
						Teleported = true
						break
					else
						task.wait(1)
					end
				end
			end
			if not Teleported then
				print("Failed to teleport "..Player.Name..", server might've shutdown!")
				Player:SetAttribute("Teleporting", nil)
				RemoveData(Player.UserId)
				Player:LoadCharacter()
			end
		end
	else
		Player:LoadCharacter()
		local Clone = Spirit.BillboardGui:Clone()
		Clone.PlayerName.Text = Player.Name
		Clone.Parent = Player.Character:WaitForChild("Head")
	end
	CharacterAdded(Player.Character)
	Player.CharacterAdded:Connect(CharacterAdded)
end

-- Check for bodies falling into void
local function CheckForBodies()
	for _,voidPart in pairs(workspace.Void:GetChildren()) do
		voidPart.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChildOfClass("Humanoid") then
				local Character = hit.Parent
				if Character:GetAttribute("OwnerId") then
					local Success = RemoveData(Character:GetAttribute("OwnerId"))
					if Success then
						Character:SetAttribute("OwnerId",nil)
					end
				elseif Players:FindFirstChild(Character.Name) then
					Players:FindFirstChild(Character.Name):LoadCharacter()
				end
			end
		end)
	end
end

-- Messaging service for alive servers
local function SubscribeToJob(targetJobId)
	pcall(function()
		MessagingService:SubscribeAsync("ServerAlive_" .. targetJobId, function(message)
			AliveServers[targetJobId] = message.Data
		end)
	end)
end

SubscribeToJob(game.JobId)

-- Keep server alive
local function ActiveServer()
	task.spawn(function()
		while task.wait(20) do
			pcall(function()
				MessagingService:PublishAsync("ServerAlive_" .. game.JobId, os.time())
			end)
		end
	end)
end

-- Initialize BodyManager
function BodyManager.Init()
	Players.CharacterAutoLoads = false
	Players.PlayerRemoving:Connect(onPlayerRemoving)
	Players.PlayerAdded:Connect(onPlayerAdded)
	CheckForBodies()
end

return BodyManager

Try using TweenService:SmoothDamp() They posted a tutorial on youtube if you don’t know how to use it
Nevermind, you want to weld the camera to it? You can probably do something like

game["Run Service"]:BindToRenderStep('WeldCamera',1,function()
	workspace.CurrentCamera.Focus={Desired CFrame here}
end)

--wait for it to complete

game["Run Service"]:UnbindFromRenderStep('WeldCamera')
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

-- Wait for character and head to exist
local function waitForHead()
	while not player.Character or not player.Character:FindFirstChild("Head") do
		task.wait()
	end
	return player.Character.Head
end

local head = waitForHead()

-- Wait for the username BillboardGui
local function waitForBillboard()
	local bb = head:FindFirstChildOfClass("BillboardGui")
	while not bb do
		task.wait()
		bb = head:FindFirstChildOfClass("BillboardGui")
	end
	return bb
end

local billboard = waitForBillboard()

-- Smoothly move camera to follow the username
local function followUsername()
	local duration = 1.2
	local startTime = tick()

	-- Store initial camera CFrame
	local startCFrame = camera.CFrame
	-- Target position matches billboard position
	local targetCFrame = CFrame.new(billboard.AbsolutePosition + Vector3.new(0,0,0), camera.CFrame.Position)

	-- Bind to render step for smooth movement
	local connection
	connection = RunService:BindToRenderStep("FollowUsername", 1, function()
		local elapsed = tick() - startTime
		local alpha = math.clamp(elapsed / duration, 0, 1)
		camera.CFrame = startCFrame:Lerp(targetCFrame, alpha)
		if alpha >= 1 then
			RunService:UnbindFromRenderStep("FollowUsername")
		end
	end)
end

followUsername()

Try placing print() statements or breakpoints around your code to make sure it’s running

so it works at camera follow script started unitl character and head found: kingofdome21 head and then no print statements after. With this current script:

local RS = game:GetService("RunService")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

print("Camera follow script started")

local char = player.Character or player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
print("Character and Head found:", char, head)

-- Try to get the BillboardGui without blocking forever
local billboard = head:FindFirstChildOfClass("BillboardGui")
if not billboard then
    print("BillboardGui not found immediately, waiting for it...")
    local conn
    conn = head.ChildAdded:Connect(function(child)
        if child:IsA("BillboardGui") then
            billboard = child
            print("BillboardGui found:", billboard)
            conn:Disconnect()
        end
    end)
    repeat task.wait() until billboard
else
    print("BillboardGui found immediately:", billboard)
end

-- Camera tween
local startCFrame = camera.CFrame
local targetCFrame = CFrame.new(billboard.Position)
local totalTime = 1.2
local elapsed = 0

local function updateCamera(dt)
    elapsed = elapsed + dt
    local alpha = math.clamp(elapsed / totalTime, 0, 1)
    camera.CFrame = startCFrame:Lerp(targetCFrame, alpha)
    if alpha >= 1 then
        print("Camera tween completed")
        RS:UnbindFromRenderStep("WeldCamera")
    end
end

print("Binding camera update to RenderStep")
RS:BindToRenderStep("WeldCamera", 1, updateCamera)

I asked gpt if it relates to the main script and it said: ChatGPT said:

Yes — the root cause is in the other script (your server BodyManager script). Specifically, the part that adds the BillboardGui to the player’s Head