How do I make the camera go with the character?

Hi, I was wondering how to make the camera go with the character, it just stays at spawn and doesn’t go with the character. Sorry if i’m bad at explaining. Any help would be appreciated

local RoundService = {}

local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

function RoundService.ChoosePlayer()
	local players = Players:GetPlayers()
	if #players == 0 then
		return warn("theres no players")
	end
	local chosen = players[math.random(1, #players)]
	print("Chosen:", chosen)
	return chosen
end

function RoundService.TeleportPlayers(cframe)
	local players = Players:GetPlayers()
	for i, player in players do
		if player.Character then
			player.Character:PivotTo(cframe)
		end
	end
end

function RoundService.CountdownAsync(duration)
	for i = duration, 1, -1 do
		workspace:SetAttribute("Clock", i)
		task.wait(1)
	end
end

function RoundService.IntermissionAsync(INTERMISSION_TIME)
	workspace:SetAttribute("Status", "Intermission")
	RoundService.CountdownAsync(INTERMISSION_TIME)
end

function RoundService.RunGameAsync(ROUND_TIME, MAP)
	workspace:SetAttribute("Status", "Game")
	
	local chosen = RoundService.ChoosePlayer()
	local MonsterModel = RS:WaitForChild("Monster")
	
	local newMonster = MonsterModel:Clone()
	
	newMonster.Name = chosen.Name
	newMonster.Parent = workspace
	
	if chosen.Character then
		chosen.Character:Destroy()
	end
	
	chosen.Character = newMonster -- I think this is the problem idk
	
	RoundService.TeleportPlayers(MAP.CFrame)
	RoundService.CountdownAsync(ROUND_TIME)
end

return RoundService

The player’s Camera.CameraSubject doesn’t automatically update when the character is manually overwritten, so in your case the camera is still tracking a character which doesn’t exist anymore. To fix this, update the camera subject when a new character is added.

Local Script

local players = game:GetService("Players")
local player = players.LocalPlayer

local function onCharacterAdded(character : Model)
	workspace.CurrentCamera.CameraSubject = character:FindFirstChild("Humanoid")
end

player.CharacterAdded:Connect(onCharacterAdded)

2 Likes

where do i add this script???

Create a new Local Script and place it in Starter Player Scripts or add it to any existing client-side system you have. It just has to run on the client, but generally it can go anywhere.

1 Like

Thank you so much!!!

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